June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
|
|
@ -0,0 +1,37 @@
|
|||
# counting sort
|
||||
|
||||
n = 10
|
||||
|
||||
dim test(n)
|
||||
test = {4, 65, 2, -31, 0, 99, 2, 83, 782, 1}
|
||||
|
||||
mn = -31
|
||||
mx = 782
|
||||
|
||||
dim cnt(mx - mn + 1) # count is a reserved string function name
|
||||
|
||||
# seems initialized as 0
|
||||
# for i = 1 to n
|
||||
# print cnt[i]
|
||||
# next i
|
||||
|
||||
# sort
|
||||
for i = 0 to n-1
|
||||
cnt[test[i] - mn] = cnt[test[i] - mn] + 1
|
||||
next i
|
||||
|
||||
# output
|
||||
print "original"
|
||||
for i = 0 to n-1
|
||||
print test[i] + " ";
|
||||
next i
|
||||
print
|
||||
print "ordered"
|
||||
for i = 0 to mx - mn
|
||||
if 0 < cnt[i] then # for i = k to 0 causes error
|
||||
for k = 1 to cnt[i]
|
||||
print i + mn + " ";
|
||||
next k
|
||||
endif
|
||||
next i
|
||||
print
|
||||
Loading…
Add table
Add a link
Reference in a new issue