单链表反序lua

local tmp = {v=1,t={v=3,t={v=10,t={v=6}}}}
function reverse(list)
local tmp;
while(list) do
tmp={v=list.v,t=tmp}
list=list.t
end
return tmp
end
function lpair(list)
return function(_,i)
if i.t then
return i.t,i.t.v
else
return
end
end,nil,{t=list}
end
for _,v in lpair(tmp) do
print(v)
end
tmp=reverse(tmp)
print(99999)
for _,v in lpair(tmp) do
print(v)
end

posted on 2014-09-21 10:30  blackCatx  阅读(129)  评论(0编辑  收藏  举报

导航