blob: bee5fd39b413703ab76983df79f03ff745caf39e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
local M = {}
local Stack = {}
function Stack:push(v)
table.insert(self._et, v)
end
function Stack:pop()
return table.remove(self._et)
end
function Stack:remove(it)
local idx = nil
for i, v in ipairs(self._et) do
if v == it then
idx = i
break
end
end
if idx == nil then
error(it .. " not in stack")
end
table.remove(self._et, idx)
end
function Stack:new()
local o = setmetatable({}, self)
self.__index = self
o._et = {}
return o
end
M.Stack = Stack
return M
|