admin管理员组

文章数量:1636896

how would you implement a secondary sorting. Meaning sorting by Category A, and then sub sorting by category B?

--------------------------------------------------------------------------


Three approaches come to mind. 
1) Sort on A, then scan the list for runs of elements with the same value for A, then sort each sublist for field B. 
2) Sort on A/B simultaneously by using a compare function or key function that uses both fields. 
3) Sort the list on B, then stable-sort the list on A. 

A nice feature of approach #1 is that you can do it lazily, i.e. only sort the sublists when the second field is queried.



本文标签: implementCareerCupsortingsecondary