Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Seven Bubble sort for you: which do you choose?
#30
For small data sets (<5000) I always use select sort.
It is easy to code.
It always works.
It always takes the same amount of time.
For larger data set some there are much better routines, but I don't understand how they work - some kind of splitting and pivoting -magic in other words.
Code: (Select All)
DefInt A-S
kdim = 32767
Dim x(kdim)
For i = 1 To kdim
    x(i) = Rnd * 1000
    Print x(i),
Next i
Print
tt = Timer
For j = 1 To kdim \ 2
    jmax = j: xmax = x(j)
    jmin = kdim - j + 1: xmin = x(kdim - j + 1)
    For i = j + 1 To kdim - j + 1
        If x(i) > xmax Then jmax = i: xmax = x(i)
        If x(i) < xmin Then jmin = i: xmin = x(i)
    Next i
    Swap x(j), x(jmax)
    Swap x(kdim - j + 1), x(jmin)
Next j
Print Timer - tt
Input sa$
For i = 1 To kdim
    Print x(i),
Next i
Print
Reply


Messages In This Thread
RE: Seven Bubble sort for you: which do you choose? - by david_uwi - 03-24-2023, 08:24 AM



Users browsing this thread: 12 Guest(s)