Table.sort - pxqwxl/myLearnPoject GitHub Wiki
今天遇到一个问题 一个数组
backingBestRoundTb = {
1 = {
"index" = 1
"shouShu" = 9
}
2 = {
"index" = 2
"shouShu" = 9
}
3 = {
"index" = 3
"shouShu" = 8
}
}
原来是这样 但是当我用
table.sort(backingBestRoundTb, function(a, b )
return a.shouShu < b.shouShu
end)
根据shouShu这个变量排序时 排序的结果成了
{
1 = {
"index" = 3
"shouShu" = 8
}
2 = {
"index" = 2
"shouShu" = 9
}
3 = {
"index" = 1
"shouShu" = 9
}
}
由此可见 table.sort并不是插入型排序 而是直接将 backingBestRoundTb[1]和 backingBestRoundTb[3]交换了位置 推测应该使用的是冒泡算法