sorting an array

Get Help on scripting in POL with configurations, config setups, script trouble shooting, etc.

Moderator: POL Developer

Post Reply
mr bubbles
Grandmaster Poster
Posts: 120
Joined: Thu Jan 18, 2007 2:34 am

sorting an array

Post 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?
dr_bliss
New User
Posts: 20
Joined: Mon Aug 07, 2006 2:02 am
Location: Poland -->Torun ->my room ->my computer

Post by dr_bliss »

write your own sort function :]
User avatar
Austin
Former Developer
Posts: 621
Joined: Wed Jan 25, 2006 2:30 am

Post 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.
mr bubbles
Grandmaster Poster
Posts: 120
Joined: Thu Jan 18, 2007 2:34 am

Post 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?
User avatar
CWO
POL Expert
Posts: 1158
Joined: Sat Feb 04, 2006 5:49 pm
Location: Chicago, IL USA

Post by CWO »

possibly because the sort is looking at them as strings instead of integers. Its putting the numbers in "alphabetical" order.
Nagl
New User
Posts: 1
Joined: Wed Apr 13, 2016 2:29 am

Re: sorting an array

Post by Nagl »

There is a method on arrays to sort them:

Code: Select all

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