require 'os'
local MAXNUM = 100000
local tab = {}
for i=1,MAXNUM do
local tmpnum = math.random(MAXNUM)
table.insert(tab, tmpnum)
end
local increasement = MAXNUM
local k=0
local i=0
local j = 0
while(increasement > 3) do
increasement = math.floor(increasement/3)
--print(">>>>>>>>22222",increasement)
for i=1, increasement do
for j=i+increasement, MAXNUM, increasement do
if tab[j]< tab[j-increasement] then
local tmp = tab[j]
k=j-increasement
while(k>0 and tmp < tab[k]) do
tab[k+increasement] = tab[k]
k=k-increasement
end
tab[k+increasement] = tmp
end
end
end
end
print(">>>>>>>>>>>>>>>>>")
for k,v in ipairs(tab) do
print("......",v)
end
lua 希尔排序
最新推荐文章于 2024-11-16 00:59:21 发布