December 04, 2020, 11:45:03 AM

### Author Topic: [bb] Bubble Sort by Naughty Alien [ 1+ years ago ]  (Read 431 times)

#### BlitzBot

• Jr. Member
• Posts: 1
##### [bb] Bubble Sort by Naughty Alien [ 1+ years ago ]
« on: June 29, 2017, 12:28:40 AM »
Title : Bubble Sort
Author : Naughty Alien
Posted : 1+ years ago

Description : ..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..

Code :
Code: BlitzBasic
1. Dim MyArray(90)
2. Global Number
3. Global Count
4. Cell_Number=41
5. Graphics 1280,1024,32,1
6. ;*** Make an array of random numbers ***
7. Cls
8. Print
9. Print "Initial random array :-"
10. Print
11.
12.
13. For Count = 1 To Cell_Number
14.         Number = Rnd (0,100)
15.         MyArray(Count) = Number
16.         Print MyArray(Count)
17. Next
18. Delay 8000
19. ;Number = UBOUND(MyArray)
20.
21. Bubblesort (Cell_Number)
22. Print
23. Print "Sorted array :-"
24. Print
25.
26. For Count = 1 To Cell_Number
27.         Print MyArray(Count)
28. Next
29. Delay 8000
30. End
31.
32.
33. Function Bubblesort(num%)
34.
35. For Count = 1 To num%
36.         For Counter = 1 To num%
37.                 If MyArray(Counter) > MyArray(Count)
38.                    SWAP=MyArray(Count)
39.                    MyArray(Count)=MyArray(Counter)
40.                    MyArray(Counter)=SWAP
41.                 End If
42.         Next
43. Next
44. End Function