Code archives/Algorithms/Bubble Sort
This code has been declared by its author to be Public Domain code.
Download source code
| |||||
..here is Bubble sort routine..maybe it will be useful for someone..me personally use it to sort distance taken from dynamic light entities (each flame have one assigned, its 34 flames on scene) and then switching only first(closest) 3 ON in order to make some nice lighting effects/normalmaping, flame flickering/..anyway, thats where i use this sorting routine..if you find it useful, take it and enjoy, othervise, just ignore this post.. :)) | |||||
Dim MyArray(90) Global Number Global Count Cell_Number=41 Graphics 1280,1024,32,1 ;*** Make an array of random numbers *** Cls Print Print "Initial random array :-" Print For Count = 1 To Cell_Number Number = Rnd (0,100) MyArray(Count) = Number Print MyArray(Count) Next Delay 8000 ;Number = UBOUND(MyArray) Bubblesort (Cell_Number) Print Print "Sorted array :-" Print For Count = 1 To Cell_Number Print MyArray(Count) Next Delay 8000 End Function Bubblesort(num%) For Count = 1 To num% For Counter = 1 To num% If MyArray(Counter) > MyArray(Count) SWAP=MyArray(Count) MyArray(Count)=MyArray(Counter) MyArray(Counter)=SWAP End If Next Next End Function |
Comments
| ||
Used it, very nice and tidy, saved me a bit of fiddling, thanks, tada! :) Dabz |
Code Archives Forum