Page 1 of 1
arrays
Posted: Wed Apr 05, 2006 7:32 am
by qrak
Any ideas how to sort two dimension array? like
Code: Select all
table.append({integervalue, stringvalue});
table.sort();
I want my script to sort by integer values, how to do it?
Posted: Thu Apr 06, 2006 4:20 am
by Bytehawk
Taken from Siggy's String Function Include, v1.3
Code: Select all
// function SortMultiArrayByIndex(MultiArray, SubIndex)
// (Function added 26-Apr-2000 by Myrathi)
// This function will sort an array of arrays (or structures) by
// the contents of the sub-index provided. So, if you have an
// array (zCoords) of [x,y,z] structures, calling the function
// with 'fn(zCoords,2)' will sort by the second sub-index... that
// is, the 'y' member. Returns '0' if the SubIndex is invalid
// (only checks against the first index)
function SortMultiArrayByIndex(MultiArray, SubIndex)
var ArrayLen:= Len (MultiArray);
if (ArrayLen < 2)
return MultiArray;
endif
if (SubIndex > len (MultiArray[1]))
return 0;
endif
var i, k, f, s;
for (i:= 1; i < ArrayLen; i:= i + 1)
for (k:= i + 1; k <= ArrayLen; k:= k + 1)
f:= MultiArray[i];
s:= MultiArray[k];
if (s[SubIndex] < f[SubIndex])
MultiArray[i]:= s;
MultiArray[k]:= f;
endif
endfor
Sleepms(2);
endfor
return MultiArray;
endfunction
Posted: Thu Apr 06, 2006 2:15 pm
by qrak
Great Thx

Don't you think that should be hardcoded in pol96?
