Sorting algorithms/Counting sort: Difference between revisions

Content deleted Content added
Line 140:
Return SubStr(t,2)
}</lang>
 
=={{header|BASIC256}}==
<lang BASIC256>
# 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
</lang>
 
=={{header|BBC BASIC}}==