local data = {}
DualStack = {}
function DualStack:new(o)
o = o or {}
self.__index =self
setmetatable(o,self)
data[o] = {}
return o
end
function DualStack:push(v)
table.insert(data[self],v)
end
function DualStack:pop()
local v = data[self][#data[self]]
table.remove(data[self],#data[self])
return v
end
function DualStack:top()
local v = data[self][#data[self]]
return v
end
function DualStack:isempty()
return #data[self] == 0
end
local stack = DualStack:new()
for i = 1, 10 do
stack:push(i)
end
print(stack:top())
while not stack:isempty() do
print(stack:pop())
end