I’ve been meaning to tweak my sorting routines to allow sorting auxillary tables so I decided to finally finish that - I’ve only completed it for string tables and only have done some basic testing.
Two subroutines attached in 9.3 basic format. I’d prefer if the QuickSortStringBySorted didn’t need an extra utility table, but couldn’t come up with a good way to sort in situ without it - I’m sure there is room for improvement. These were modified from the subroutines I posted here: Faster table sorting with quick-sort algorithm
//stTabletoSortBy should contain the string data that you want all tables to sort by
//nStartIndex and nEndIndex is the range of the table you want to have sorted.
//nStartIndex is most likely 0, and nEndIndex should be the last value in your tables to sort.
//Descending should be 0 for A to Z and 1 if you want to sort Z to A
//ntSortedOrder is an integer table that stores how the string table was sorted to be used in the other subroutine. It should be the same length as the string table.
//ntWorkSortedOrder should be the same length as ntSortedOrder and is a utility table used in the subroutine during the sort.
//This call to QuickSortString_v2 will sort the initial table - the one you want to sort everything by
//and will also setup the ntSortedOrder so we can sort other tables the same way
QuickSortString_v2(stTableToSortBy, nStartIndex, nEndIndex, Descending, ntSortedOrder);
//This will sort the stSiblingTableToSort1 in the same order as stTableToSortBy
QuickSortStringBySorted(stSiblingTableToSort1, nStartIndex, nEndIndex, ntSortedOrder, ntWorkSortedOrder);
//This will sort the stSiblingTableToSort2 in the same order as stTableToSortBy
QuickSortStringBySorted(stSiblingTableToSort2, nStartIndex, nEndIndex, ntSortedOrder, ntWorkSortedOrder);
//Sort additional tables as needed
MultiTableStringQuicksort9.3Basic.zip (9.4 KB)