masheen wrote:Plz help. I have array with coordinates.
Code: Select all
Array := []
Array[1,1] := 4844.2578125000 ;x
Array[1,2] := 4740.5839843750 ;y
Array[2,1] := 4860.1962890625 ;x
Array[2,2] := 4724.5092773438 ;y
Array[3,1] := 4876.6328125000 ;x
Array[3,2] := 4726.5429687500 ;y
Array[4,1] := 4893.0820312500 ;x
Array[4,2] := 4726.9536132813 ;y
Array[5,1] := 4905.8173828125 ;x
Array[5,2] := 4721.2353515625 ;y
MsgBox % Array.Length()
Question: How to sort it (ASC)?
I am not totally sure how you want them sorted but if you are talking about sorting them by the x or y value, here is an example.
Code: Select all
Array := []
Array[1,1] := 4844.2578125000 ;x
Array[1,2] := 4740.5839843750 ;y
Array[2,1] := 4860.1962890625 ;x
Array[2,2] := 4724.5092773438 ;y
Array[3,1] := 4876.6328125000 ;x
Array[3,2] := 4726.5429687500 ;y
Array[4,1] := 4893.0820312500 ;x
Array[4,2] := 4726.9536132813 ;y
Array[5,1] := 4905.8173828125 ;x
Array[5,2] := 4721.2353515625 ;y
SortedBy1 := Sort_Array(Array,1) ;x
SortedBy2 := Sort_Array(Array,2) ;y
Sort_Array(Arr, By)
{
Temp := {}
for k, v in Arr
Temp[v[By]] := v
Arr := {}
for k, v in Temp
Arr.Push(v)
return Arr
}
This is sorting them as strings and not numbers so it is just a start. Stuff like 98.76 vs 123.4 might give unexpected results. You could pad the left with zeros to make all the numbers the same length for better number sort results.
FG