Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sorting numbers - FiliSort
#1
Code: (Select All)

' FiliSort v1.0
' This a very simple sorting method, a lot faster than Bubblesort
' For 50000 numbers in my pc, it takes 16.43 sec
' while the Bubble Sort takes 29.18 sec

Screen _NewImage(800, 700, 32)

Dim Shared tn As Long
tn = 20000 ' total numbers to sort
Dim Shared n(tn) As Single

Randomize Timer
For i = 1 To tn: n(i) = Rnd * 100 - 50: Next i

timer1! = Timer
Print "Sorting..."; tn; "numbers": Print "Timer starts:"; timer1!

FiliSort n()

timer2! = Timer
Print "Timer ends:"; timer2!; "    Seconds:"; (timer2! - timer1!) / 1.18

'For k = 1 To tn: Print n(k): Next k

End

Sub FiliSort (n())
    For k = 1 To tn / 2
        min = n(k): max = n(tn - k + 1)
        imin = 0: imax = 0
        For i = k To tn - k
            If min > n(i + 1) Then min = n(i + 1): imin = i + 1 'find the minimum of the numbers
            If max <= n(i) Then max = n(i): imax = i 'find the maximum of the numbers
        Next i
        If imin > 0 Then n(imin) = n(k): n(k) = min
        If imax = k Then imax = imin
        If imax > 0 Then n(imax) = n(tn - k + 1): n(tn - k + 1) = max
    Next k
End Sub
Reply


Messages In This Thread
Sorting numbers - FiliSort - by 2112 - 03-08-2026, 04:34 PM
RE: Sorting numbers - FiliSort - by bplus - 03-08-2026, 05:38 PM
RE: Sorting numbers - FiliSort - by bplus - 03-08-2026, 05:55 PM
RE: Sorting numbers - FiliSort - by SMcNeill - 03-08-2026, 06:55 PM
RE: Sorting numbers - FiliSort - by bplus - 03-08-2026, 07:27 PM
RE: Sorting numbers - FiliSort - by 2112 - 03-08-2026, 06:51 PM
RE: Sorting numbers - FiliSort - by SMcNeill - 03-08-2026, 07:06 PM
RE: Sorting numbers - FiliSort - by PhilOfPerth - 03-10-2026, 08:19 AM
RE: Sorting numbers - FiliSort - by SMcNeill - 03-10-2026, 09:21 AM
RE: Sorting numbers - FiliSort - by PhilOfPerth - 03-10-2026, 10:17 PM
RE: Sorting numbers - FiliSort - by bplus - 03-10-2026, 10:46 PM
RE: Sorting numbers - FiliSort - by PhilOfPerth - 03-11-2026, 12:48 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Using the tenary operator in C with 3 numbers Kernelpanic 16 4,259 09-13-2024, 06:06 AM
Last Post: Jack
  Test sorting algorithms eoredson 3 1,014 05-04-2023, 09:38 PM
Last Post: eoredson
  Serial Numbers AtomicSlaughter 1 807 03-13-2023, 05:45 PM
Last Post: mnrvovrfc

Forum Jump:


Users browsing this thread: 1 Guest(s)