Lua快排

来源:互联网 发布:中国最后一个太监知乎 编辑:程序博客网 时间:2024/06/06 00:50
--[[文件名: 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 thenreturn trueendif _l_item.TOTAL_RIGH == _r_item.TOTAL_RIGH thenif _l_item.USE_TM >= _r_item.USE_TM thenreturn trueendreturn falseendreturn falseendlocal function DoSortScore( _t_item, _l, _r )if _l < _r thenlocal mid_val = _t_item[_l]local i = _llocal j = _rwhile 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 ) doj = j - 1endif i < j then_t_item[i] = _t_item[j]endwhile i < j and IsNeedFront( mid_val, _t_item[i] ) doi = i + 1endif i < j then_t_item[j] = _t_item[i]endend_t_item[i] = mid_valDoSortScore( _t_item, _l, i-1 )DoSortScore( _t_item, i+1, _r )endendDoSortScore( _sort_list, 1, table.getn(_sort_list) )endG_LIMIT = 1000g_sort_list = {}for i=1, G_LIMIT dog_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 )endprint( "--------------" )SortScore( g_sort_list )print( "--------------" )for i=1, G_LIMIT doprint( i, g_sort_list[i].TOTAL_RIGH, g_sort_list[i].USE_TM )end

0 0
原创粉丝点击