LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Should SortTableCells leave equivalent strings in original order?

When I call SortTableCells on a string column and the strings are equivalent, can I expect that this function will leave the table cells in their original order when the strings are equal?  It looks like they are not in the original order.  Is there an option where I can force this to happen?
Thanks,
Donna
0 Kudos
Message 1 of 2
(2,799 Views)
Unfortunately, there isn't. SortTableCells uses the quicksort algorithm for sorting the cells, and this algorithm does not guarantee that it preserves the order of identical items. If you need this characteristic, you will have to sort the cells yourself using the Programmer's Toolbox InsertionSort function. It uses a slower algorithm (this might not be a concern for you if you don't have that many items), but it guarantees that the order is maintained.

Of course, manually sorting the cells yourself means that you will have to first get all the values you want to sort from the table, store them in an array which you can pass to the sort function, and then re-insert them back into the table in the right order. If your sort affects more than one column, it's a bit more complicated. In that case, your best bet is probably to remember the original row of each item, and then when you are reinserting them back into the table, you have to "move" each row from its original location into its new location.

Luis
NI
0 Kudos
Message 2 of 2
(2,788 Views)