Post by johnno56 on May 28, 2023 21:19:02 GMT -6
I am working my way through some of the "Rosetta Code" sort routines (as a possible source for a sorting library?) when I came across a sort routine that, in my opinion, does not run "quite right". I would request that as many people test this routine so as to confirm my results.
The routine is a "Comb Sort" ( rosettacode.org/wiki/Sorting_algorithms/Comb_sort#Liberty_BASIC )
Start with itemCount = 10000 (default) and record your time.
Sorting 10,000 items in RCBasic should be enough for most uses... My result was 0.1 seconds... I thought that there may be a problem or a typo but then, just out of curiosity, I changed itemCount to equal 100,000 - result: 1.292 Seconds... Then thought, "Why not?" and jumped it up to 1,000,000 - result: 14.923 seconds.
The other sort routines that I have converted have not been anywhere near these results. I just need to find out if this routine is as fast as I think it is or just a fluke mistake...
Thanks.
J
The routine is a "Comb Sort" ( rosettacode.org/wiki/Sorting_algorithms/Comb_sort#Liberty_BASIC )
xmax = 640
ymax = 480
title$ = "Comb Sort"
center_x = windowpos_centered
center_y = windowpos_centered
WindowOpen(1,title$,center_x,center_y,xmax,ymax,WindowMode(1,0,0,0,0),1)
SetWindowAutoClose(1, 0)
CanvasOpen(1,xmax,ymax,0,0,xmax,ymax,0)
ClearCanvas
randomize(timer)
itemCount = 10000
dim item[itemCount + 1]
for i = 1 to itemCount
item[i] = rand(1000)
'print str(item[i])
next
'print ""
start = timer
print "Sorting..."
swaps = 0
gap = itemCount
while gap > 1 or swaps <> 0
gap = int(gap / 1.25)
'if gap = 10 or gap = 9 then
' gap = 11 'uncomment to get Combsort11
'end if
if gap < 1 then
gap = 1
end if
i = 1
swaps = 0
for i = 1 to itemCount - gap
if item[i] > item[i + gap] then
temp = item[i]
item[i] = item[i + gap]
item[i + gap] = temp
swaps = 1
end if
next
wend
finish = timer - start
'for i = 1 to itemCount
' print item[i]
'next
print ""
print "Done..."
print ""
print "Time: " + str(finish / 1000) + " seconds."
if Not WindowExists(1) Or WindowEvent_Close(1) Then
end
end if
update()
Start with itemCount = 10000 (default) and record your time.
Sorting 10,000 items in RCBasic should be enough for most uses... My result was 0.1 seconds... I thought that there may be a problem or a typo but then, just out of curiosity, I changed itemCount to equal 100,000 - result: 1.292 Seconds... Then thought, "Why not?" and jumped it up to 1,000,000 - result: 14.923 seconds.
The other sort routines that I have converted have not been anywhere near these results. I just need to find out if this routine is as fast as I think it is or just a fluke mistake...
Thanks.
J