03-02-2006, 08:54 AM
Code:
declare sub radix(digit as integer, a() as integer, outpt() as integer, size as integer)
declare sub radixsort(a() as integer, outpt() as integer, size as integer)
'********Test Radix sort**************
redim testarray(13)
redim outputarray(13)
testarray(0) = 1
testarray(1) = 5
testarray(2) = 55
testarray(3) = 57
testarray(4) = 128
testarray(5) = 157
testarray(6) = 152
testarray(7) = 9
testarray(9) = 25
testarray(10) = 22
testarray(11) = 166
testarray(12) = 167
testarray(13) = 168
radixsort testarray(0), outputarray(0), 13
for i = 0 to 13
print outputarray(i)
next
sleep
end
sub radixsort(a() as integer, outpt() as integer, size as integer)
radix 10, a(0), outpt(0), size
'the longest an integer can be is 10 digits
End Sub
sub radix(digit as integer, a() as integer, outpt() as integer, size as integer)
If digit < 0 or size <= 0 Then exit sub 'base case
DIM temp(9, size) as integer
Dim stacktop(9) as integer
FOR i = 0 TO size
b = (a(i) \ (10 ^ digit)) mod 10 'get the digit-th place
temp(b, stacktop(b)) = a(i)
stacktop(b) = stacktop(b) + 1
Next
FOr i = 0 to 9
radix digit - 1, temp(0, i), temp(0, i), stacktop(i)
next
top = 0
For i = 0 To 9
For j = 0 To size
If temp(i, j) Then
outpt(top) = temp(i,j)
top = top + 1
end if
next
next
End Sub
I can't get this thing to work right. Its supposed to be a radix sort without Linked Lists, but I just can't get it to sort correctly, it also for some reason copies the value 22.[/code]
f you play a Microsoft CD backwards you can hear demonic voices. The scary part is that if you play it forwards it installs Windows.