• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

URGENT! in Visual Basic, how do I bubblesort?

Have you done a Bubble Sort before? Do you have an example of a Bubble Sort?

It's been a long time since I did any kind of sort and quite frankly I'd be stumped without taking a refresher course, but sorting methods are basically a collection of commands organized in a certain fashion. Figure out each step, then re-write them in Basic.

If you have no idea what a Bubble sort is, then good luck.

PS: you may want to check out your text books.
 
I can only help you with an example from my class. If you were using a bubble sort to alphabetize the names Pay, Bob, Willy, Fred, Dave it would look like this. This doesn't format right, but you get the idea.



<< Dim nom(1 to 5) As String

Private Sub cmdSort_Click()
..Dim passNum As Integer, i As Integer, temp As String
....For passNum = 1 to 4
.......For i = 1 to 5 - passNum
...........If nom(i) > nom(i + 1) Then
..............temp = nom(i)
..............nom(i) = nom(i + 1)
..............nom(i+1) = temp
...........End If
.......Next i
....Next passNum
..For i = 1 to 5
.....picNames.print nom(i),
..Next i
End Sub
>>



The periods are just place holders so fusetalk formats correctly.

This is assuming you have an array with the names in it. Basically what happens is this
1)It compars the 1st and 2nd items, then if they are out of order it swaps them
2)It compares the 2nd and 3rd items, then if they are out of order it swaps them.
3)Keep repeating this for the rest of the pairs. The final comparison and swap are with the second-to-last and last elements.
 
Back
Top