前言
正文内代码
6.1
#!/usr/bin/lua
function put(array)
print(table.unpack(array))
end
6.2
#!/usr/bin/lua
function foo(...)
return select(2,...)
end
6.3
#!/usr/bin/lua
function foo(...)
local arg=table.pack(...)
arg[arg.n]=nil
arg.n=arg.n-1
return table.unpack(arg)
end
6.4
分别用lua、c及shell实现,见仓库
6.5
#!/usr/bin/lua
function arrange(tab,begin)
begin=begin or 0
if begin==0 then
main_index=1
end
if main_table==nil or begin==0 then
main_table={}
end
if sub_table==nil or begin==0 then
sub_table={}
end
if begin==(#tab) then
main_table[main_index]=table.move(sub_table,1,#sub_table,1,{})
main_index=main_index+1
else
table.insert(sub_table,tab[begin+1])
arrange(tab,begin+1)
table.remove(sub_table)
arrange(tab,begin+1)
end
return main_table
end
注:参考了他人的算法
6.6
待完善