Page 1 of 1

sorting an array

Posted: Wed Jun 13, 2007 12:47 am
by mr bubbles
hi basically i just have props stored in a file with their names as numbers. Pol sorts numbers like (10, 100, 11, 12, 13, 14) etc. Is there any way to sort the numbers in a numericaly correct sequence?

Posted: Wed Jun 13, 2007 4:13 am
by dr_bliss
write your own sort function :]

Posted: Wed Jun 13, 2007 4:43 am
by Austin
http://linux.wku.edu/~lamonml/algor/sort/sort.html

Easiest to code is insert sort (dont use bubble its very slow)
The best for POL scripting would probably be merge sort.

Posted: Wed Jun 13, 2007 6:45 am
by mr bubbles
i was just looping through the array of numbers something like this

newarray := oldarray
foreach prop in newarray
oldarray[prop] := prop;
endforeach

since all the prop names were the numbers i wanted sorting.

anyway, why does the sort function sort that that?

Posted: Wed Jun 13, 2007 7:03 am
by CWO
possibly because the sort is looking at them as strings instead of integers. Its putting the numbers in "alphabetical" order.

Re: sorting an array

Posted: Wed Apr 13, 2016 2:32 am
by Nagl
There is a method on arrays to sort them:

Code: Select all

var arr := array{3,2,1};
arr.sort();