10-20-2023, 07:36 PM
Best Bubble Sort
|
10-20-2023, 07:43 PM
(10-20-2023, 07:36 PM)dbox Wrote: I just saw where Spriggsy posted this great new algorithm. This is cool but where does the title of this thread come from? I was all set to b... about Bubble Sort! ;-))
b = b + ...
10-20-2023, 09:21 PM
"However, better sort algorithms exist."
-- Herbert Schildt, The Art of C Something was said by him at least three times, while he also went over selection sort and something else that wasn't quick sort. LOL at "best" bubble sort, it's like choosing a beer for the "best" bubbles and never drinking it. (raises hand)
Best bubbles got it!
b = b + ...
10-24-2023, 06:00 PM
10-24-2023, 07:06 PM
(10-24-2023, 06:00 PM)NakedApe Wrote: ... While looks for Boolean expression that evaluates to 0 or not 0 eg 1 So While 1 sets up an infinite loop that needs an escape clause inside it or depends on top right X box to close program. Better would have been: While _KeyDown(27) = 0 bubble was from some really old code, 6 years I think, ya live, ya learn if you do well.
b = b + ...
10-24-2023, 07:42 PM
(10-24-2023, 06:00 PM)NakedApe Wrote: That's cool and so few lines of code. I don't get your loop starting WHILE 1 ... WEND though. How does that work? While what's 1? Scratches head . . . It actually creates an endless loop. It is assumed that inside the loop, there is a condition to break out of it. However, `WHILE... WEND` is not recommended to be used in this programming system simply because there is no `EXIT WHILE`. Freebasic could do that, but QB64 cannot. Therefore, the recommended thing is: Code: (Select All) DO WHILE 1 With `DO... LOOP` it is also possible to do `LOOP WHILE 0` or `LOOP UNTIL 1`, then in that case you have a "loop" that executes once. This is ideal when you have a deeply-nested loop and well within, you need to break out of all the levels with `EXIT DO`. I learned about this in the QB64 Wiki. The "condition", as bplus already said, should involve getting a keypress from the user, especially ESCAPE key, to get out of the program.
10-24-2023, 07:59 PM
>"It actually creates an endless loop. It is assumed that inside the loop, there is a condition to break out of it. However, `WHILE... WEND` is not recommended to be used in this programming system simply because there is no `EXIT WHILE`. Freebasic could do that, but QB64 cannot."<
QB64 can EXIT WHILE don't mislead please Code: (Select All) While 1
b = b + ...
10-31-2023, 07:30 PM
Thanks for the replies!
|
« Next Oldest | Next Newest »
|
Users browsing this thread: 1 Guest(s)