生活随笔
收集整理的這篇文章主要介紹了
稳定多维table排序
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
?
?穩定的多維條件數組排序?由調用者保證tbCondition的元素個數大于等于維度nDimension?]]?function?MutilArraySort(tbCondition,?nDimension)?????local?tbResult?=?{}?????for?i?=?1,?#tbCondition?do?????????local?nInsert?=?0?????????local?nLocal?=?1?????????for?k?=?1,?nDimension?do?????????????local?function?DimensionCompare(j)?????????????????if?j?>?#tbResult?then?????????????????????return?#tbCondition?+?1?????????????????end?????????????????if?tbCondition[i][k]?>?tbCondition[tbResult[j]][k]?then?????????????????????return?j?????????????????elseif?tbCondition[i][k]?==?tbCondition[tbResult[j]][k]?then?????????????????????return?0,?j?????????????????else?????????????????????return?DimensionCompare(j?+?1)?????????????????end?????????????end?????????????nInsert,?nLocal?=?DimensionCompare(nLocal)?????????????if?nInsert?>?0?and?nInsert?<=?#tbResult?then?????????????????table.insert(tbResult,?nInsert,?i)?????????????????break?????????????elseif?nInsert?>?#tbResult?then?????????????????table.insert(tbResult,?i)?????????????????break?????????????end?????????????if?k?==?nDimension?then?????????????????table.insert(tbResult,?i)?????????????????break?????????????end?????????end?????end?????return?tbResult?end??tbCondition?=?{?????[1]?=?{?1,?2,?6,?6?},?????[2]?=?{?5,?2,?8,?5?},?????[3]?=?{?5,?2,?7,?6?},?????[4]?=?{?5,?2,?1,?4?},?}?local?tbResult?=?MutilArraySort(tbCondition,?4)?for?i?=?1,?#tbResult?do?????print(tbResult[i])?end? ?
轉載于:https://blog.51cto.com/rangercyh/1160537
總結
以上是生活随笔為你收集整理的稳定多维table排序的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。