Then the Bubble_sort() proc which I got off the forums here is supposed to sort it by its values.
But it doesn't work.
mob/verb/testthingy()
var/list/l=new
for(var/v in 1 to 20)
l["[rand(1,9999)]"]=rand(1,9999)
l=Bubble_sort(l)
src<<"sorted values:"
for(var/v in 1 to l.len)
src<<l[l[v]]
proc/Bubble_sort(list/l)
var i, j
for(i=l.len,i>0,i--)
for(j=1,j<i,j++)
if(l[j]>l[j+1])
l.Swap(j,j+1)
return l
Here is what it prints out.
sorted values:
1257
594
561
8262
7711
2321
5629
4035
3933
4842
4601
997
2132
8482
7083
8238
6130
1289
3468
7981
Why doesn't it work? I've tried about 5 of the sorting procs I found on these forums and none of them work. Thanks
For example I tried these ones too:
proc/Sort_by_associative_value(list/l)
if(l.len<=1) return l
for(var/x=1,x<=l.len,x++)
for(var/remain=l.len,remain>1,remain--)
if(l[remain-1]<l[remain]) //change this line to if(l[remain-1]>l[remain]) for ascending order
l.Swap(remain-1,remain)
return l
proc/Sort_by_associative_value(list/l)
var/min,i,j
for(i=1 to l.len-1)
min=l[l[i]]
for(j=i+1 to l.len)
if(l[l[j]]<min)
min=j
l.Swap(i,min)
return l