--[[
文件名 : C++入口.lua
作者 : 陈泽丹
创建时间: 2013-11-1
描述 :
--]]
--得分排名
function SortScore( _sort_list )
local function IsNeedFront( _l_item, _r_item )
if _l_item.TOTAL_RIGH < _r_item.TOTAL_RIGH then
return true
end
if _l_item.TOTAL_RIGH == _r_item.TOTAL_RIGH then
if _l_item.USE_TM >= _r_item.USE_TM then
return true
end
return false
end
return false
end
local function DoSortScore( _t_item, _l, _r )
if _l < _r then
local mid_val = _t_item[_l]
local i = _l
local j = _r
while i < j do
--print( i, g_sort_list[i].TOTAL_RIGH, g_sort_list[i].USE_TM )
--print( j, g_sort_list[j].TOTAL_RIGH, g_sort_list[j].USE_TM )
while i < j and IsNeedFront( _t_item[j], mid_val ) do
j = j - 1
end
if i < j then
_t_item[i] = _t_item[j]
end
while i < j and IsNeedFront( mid_val, _t_item[i] ) do
i = i + 1
end
if i < j then
_t_item[j] = _t_item[i]
end
end
_t_item[i] = mid_val
DoSortScore( _t_item, _l, i-1 )
DoSortScore( _t_item, i+1, _r )
end
end
DoSortScore( _sort_list, 1, table.getn(_sort_list) )
end
G_LIMIT = 1000
g_sort_list = {}
for i=1, G_LIMIT do
g_sort_list[i] = {}
g_sort_list[i].TOTAL_RIGH = math.random( 1, 30 )
g_sort_list[i].USE_TM = math.random( 1, 10 )
--print( g_sort_list[i].TOTAL_RIGH, g_sort_list[i].USE_TM )
end
print( "--------------" )
SortScore( g_sort_list )
print( "--------------" )
for i=1, G_LIMIT do
print( i, g_sort_list[i].TOTAL_RIGH, g_sort_list[i].USE_TM )
end