链接已复制
5 回复数
>>The first question to ask is: what is a sorted 2d array for you?
right
do you want to sort the "rows" based on values(keys) in one or more columns?
do you want to sort the "columns" based on values(keys) in one or more rows?
do you want each row to have its columns sorted?
do you want each column to have itsrows sorted?
do you want the entire 2d array sorted as calender dates?
(i.e. as if all rows were concatinated in order then having columns sorted, then uncatinated).
These are but 5 differentorders forsorting a 2D array.
(there areother sort orders too)
Jim Dempsey
right
do you want to sort the "rows" based on values(keys) in one or more columns?
do you want to sort the "columns" based on values(keys) in one or more rows?
do you want each row to have its columns sorted?
do you want each column to have itsrows sorted?
do you want the entire 2d array sorted as calender dates?
(i.e. as if all rows were concatinated in order then having columns sorted, then uncatinated).
These are but 5 differentorders forsorting a 2D array.
(there areother sort orders too)
Jim Dempsey
Also,
Assume your 2D array is dimension x and where m and n are very large.
Assume youwant to order the rows based on the values contained within one column.
In this case it may be most efficient to produce a 1D vector of indexes to the rows.
This does not require copying/moving the row data. Assume this sorted vector is v
access (after sort) is x[ v ]
This also has a benefit in that multiple views (sorts) of the data can be made or used concurrently.
Jim Dempsey
Assume your 2D array is dimension x
Assume youwant to order the rows based on the values contained within one column.
In this case it may be most efficient to produce a 1D vector of indexes to the rows.
This does not require copying/moving the row data. Assume this sorted vector is v
access (after sort) is x[ v ]
This also has a benefit in that multiple views (sorts) of the data can be made or used concurrently.
Jim Dempsey