ID:139276
 
Code:
mob
verb
test()
var/list/l = list(20,40,30,50,10)
for(var/x = 1 to 5)//length(l)
if(l[x]>l[x+1])
world <<"Swapping [l[x]] and [l[x+1]]"
l.Swap(x,x+1)
world << l[x]

else
world << l[x]


Problem description: I'm trying to make this code put these numbers in order then display them

Search Wikipedia for "sorting algorithms". Here is a simple one you could use:

proc/sort(list/l)
for (var/i=1,i<=l.len,i++)
for(var/j=l.len, j>i, j--)
if (l[j-1] > l[j])
var/t = l[j-1]
l[j-1] = l[j]
l[j] = t


Call it on the list and it will be sorted.
In response to Toadfish
Thanks so much. Trying to understand that algorithm is making my head spin.
In response to Lilcloudy1
I wrote it quickly and the code is unclear, so don't worry about it. The algorithm I wrote is called a "bubble sort", and you can find an explanation of it here: http://en.wikipedia.org/wiki/Bubble_sort.