Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

suggestion on bubble sort

Status
Not open for further replies.

mpaone12

Technical User
Oct 15, 2000
13
US
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
 
Let's see if this auto-link system works --

FAQ answer to the QuickSort:

faq314-336
 
Here is an overview of the various sort methods. The references are for Visual Basic but the same *BASIC* concepts (and usually, syntax apply):


I guess it should be no surprize to many that, in some instances, the Bubble Sort can be several times faster than the Quick Sort.
VCA.gif

Alt255@Vorpalcom.Intranets.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top