1、构建新表排序法
--table 1 用户座椅ID
local szChairID={1,2,3,4,5}
--table 2 用户分数表
local szScore={-9,20,7,-19,1}
--这个时候用户座椅和用户分数一一对应
--但是要让分数从大到小显示
local usercount=5
--新建一个临时表
local table_UserInfo={}
--赋值
for i=1,usercount do
table_UserInfo[i]={}
table_UserInfo[i].ChairId=szChairID[i]
table_UserInfo[i].Score=szScore[i]
end
--排序
table.sort(table_UserInfo,function(a,b) return a.Score > b.Score end)
--使用
for i in inspire(table_UserInfo) do printf("|ChairID:"..table_UserInfo.ChairId.."|".."Score:"..table_UserInfo.Score.."|")
end
2、键排序