Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

HOW DO I SORT A LIST OF ELEMENTS USING BUBBLE SORT.

I'm now seeing the algorithm is slightly different from the one I use. Sorry; I said nothing...

Like Victor said, it's the way you do the code...

First you have to had two index, to point to the two numbers of the array [a bunch of numbers that you wanna sort] like...

N1 .. N2 .. N3 .. N4 .. N5 .. N6 .. N7 .. N8

Then lets do it like this... INDEX1 will go from MINNUM+1 to MAXNUM and INDEX2 will go from MAXNUM downto INDEX1, so you use INDEX1 to remeber from where to where you allready did the comparations of the numbers and INDEX2 to do the comparations numbers

For Index1:=MinNum+1 To MaxNum Do

For Index2:=MaxNum DownTo Index1 Do

If MyArray[Index2-1] > MyArray[Index2] Then

ChangePlaces(MyArray[Index

So for the sorting of the numbers up there [N1 .. N8]: Index1 points to N2 and Index2 points to N8…

Index1 Index2 Comparation

N2 N8 If N7 > N8 then change

N2 N7 If N6 > N7 then change

N2 N6 If N5 > N6 then change

N2 N5 If N4 > N5 then change

N2 N4 If N3 > N4 then change

N2 N3 If N2 > N3 then change

N2 N2 If N1 > N2 then change

At this moment we reach the "bottom" set it at MINNUM+1 or N2 or Index1, you see that every number had been compared with the next closest one from up-to-down-comparation… then we set the bottom to N3 or we just increment Index1, and Ïndex2 we set it to the top

N3 N8 If N7 > N8 then change

N3 N7 If N6 > N7 then change

N3 N6 If N5 > N6 then change

N3 N5 If N4 > N5 then change

N3 N4 If N3 > N4 then change

N3 N3 If N2 > N3 then change

Again at this moment we reach the bottom set it at N3 and we did the comparations and again we set the Index1 to the what it was + 1 (we increase the bottom) and again we set the Index2 to the top…

N4 N8 If N7 > N8 then change

And so on until we reach

N8 N8 If N7 > N8 then change

http://www.experts-exchange.com/Customer_Service/Experts_Exchange/Q.10151692

All Courses

From novice to tech pro — start learning today.

For I := 1 to n - 1 do

Begin

For J := i to n - 1 do

If X[j] > X[j+1] then

Begin

T := X[j];

X[j] := X[j+1];

X[j+1] := T

end

end

of course, you'll need to declare all the variables here.