mergeSort(list/l)
if(l.len <= 1) return l // list is already sorted
var/mid = floor(l.len/2)
var/list/left = mergeSort(l.Copy(1, mid+1))
var/list/right = mergeSort(l.Copy(mid+1))
var/list/result = new
while(left.len > 0 && right.len > 0)
if(left[1] <= right[1])
result += left[1]
left.Cut(1,2)
else
result += right[1]
right.Cut(1,2)
if(left.len > 0) result += left
else if(right.len > 0) result += right
return result
bubbleSortA(list/l) // everything in this list should be a number
if(!l.len) return
var i, j, temp, num = l.len
for(i=0,i < num, i++)
for(j=1, j < (num - i), j++)
if(l[j] > l[j + 1])
temp = l[j]
l[j] = l[j + 1]
l[j + 1] = temp
return l
Wrote these today, and they are bug free as far as I've tested. After profiling them by running through 20 numbers each time I (spam) click a verb that calls them, and they apparently use 0% CPU. I had no idea sorting could be so easy after the concept is grasped. Feel free to use these in whatever way necessary. If you like math, these are awfully nifty for calculating medians.