SortWidth with Variable Num of Arrays

Is there a way to use Area.SortWith with a variable number of arrays only known at runtime?

-karen

Karen, I can think of 2 ways to do it… is it guaranteed that the arrays all have the same count (number of items), or must this work with arrays of different count ?

One is to write your own Quicksort routine which accepts an array of arrays, and use .Introspection.TypeInfo to find out how many arrays were passed and the details of each one, and, using Quicksort, reorganise them all concurrently.

Another way is to use:

  • one array eg, namesArray() which is the first one you want to sort,
  • a second array which will act as a cross-reference “indexArray”, which is initialised with integers 0…(n-1), these correspond to the original order of the namesArray.

then:

namesArray.sortWith(indexArray) // will re-order the index. The rest of the arrays are not sorted, at all.

// To access data in the rest of the arrays corresponding to “aName”:

i as integer = namesArray.indexOf(aName)
if i > -1 then
index as integer = indexArray(i)
attribute1 = anotherArray1(index) // this array is not sorted
attribute2 = anotherArray2(index) // nor this…
attribute3 = anotherArray3(index) // nor this…

endIf

Using arrays like this is dangerous, however …

You can use an in-memory SQLite database and sort as you want.

Thanks! Good suggestions, but I went different route.

I was importing data from a CSV file line by line, and was able to find a way to sort the lines before parsing the fields into separate arrays, so the arrays are already in order when created.

Thanks,
-Karen