a={}
for i=1,10 do
a[i]={}
for j=0,10 do
if(i%2==0) then
a[i][j]=0
end
end
end
print(a[9][10])
print(a[10][10])
print()
–双端队列
List={}
function List.new()
return {first=0,last=-1}
end
function List.pushleft(list,value)
local first=list.first-1
list[first]=value
list.first=first
end
function List.pushright(list,value)
local last=list.last+1
list[last]=value
list.last=last
end
function List.popleft(list)
local first=list.first
if(first>list.last) then
error(“list is empty”)
end
local res=list[first]
list[first]=nil
list.first=list.first+1
return res
end
function List.popright(list)
local last=list.last
if last<first then
error(“the list is empty”)
end
local res=list[last]
list[last]=nil
list.last=list.last-1
return res
end
function List.display(list)
if(list.first>list.last) then
error(“the list is empty”,2)
end
for i=list.first ,list.last do
print(list[i])
end
end
mylist=List.new()
List.pushleft(mylist,12)
List.pushleft(mylist,”00″)
List.pushright(mylist,34)
List.pushright(mylist,56)
List.display(mylist)
print()
function newStack ()
return
a[2]=a — 循环表
a.z=a[1] — 共享子表
save(‘a’,a)