sorry, i'm a little late on this post, so if anyone reads this...we just did bubble sorts in school (i'm a youngin) and this is how we were taught, but i'm sure the ways that you guys suggested are much more efficient..so i'm just offering this as an example as how they're teaching us in skool..trash the teaching methods at will |-0
for i = 1 to 10
read a(i) 'read the data
next i '(could be inputed too of course =)
for times = 1 to 10
for i = 1 to 9
if a(i) < a(i+1) then goto skip
t = a(i)
a(i) = a(i+1)
a(i+1) = t
skip: next i
next times
for i = 1 to 10: Print a(i): next i '(optional)
This method just stores the first variable into a temporary variable (t) so that when you compare with the next varible in the array it doesn't get reversed and you don't end up with the same number you started with. Also the goto is so that if it is already less than the next variable, it will skip that one (saves some time i supose). any comments/suggestions? oh, the quicksort method suggested in the previous posts looks pretty impressive, maybe they should teach us that instead LOL
for i = 1 to 10
read a(i) 'read the data
next i '(could be inputed too of course =)
for times = 1 to 10
for i = 1 to 9
if a(i) < a(i+1) then goto skip
t = a(i)
a(i) = a(i+1)
a(i+1) = t
skip: next i
next times
for i = 1 to 10: Print a(i): next i '(optional)
This method just stores the first variable into a temporary variable (t) so that when you compare with the next varible in the array it doesn't get reversed and you don't end up with the same number you started with. Also the goto is so that if it is already less than the next variable, it will skip that one (saves some time i supose). any comments/suggestions? oh, the quicksort method suggested in the previous posts looks pretty impressive, maybe they should teach us that instead LOL