123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- ---
- --- Generated by EmmyLua(https://github.com/EmmyLua)
- --- Created by xxn.
- --- DateTime: 2020/10/13 10:28
- ---
- Stack = {}
- Stack.__index = Stack
- local tinsert = table.insert
- function Stack:New()
- local o = {dataTb = {}}
- setmetatable(o, self)
- return o
- end
- function Stack:Push(...)
- local arg = {...}
- self.dataTb = self.dataTb or {}
- if next(arg) then
- for i = 1, #arg do
- tinsert(self.dataTb, arg[i])
- end
- end
- end
- function Stack:Pop(num)
- num = num or 1
- assert(num > 0, "num必须为正整数")
- local popTb = {}
- for i = 1, num do
- tinsert(popTb, self.dataTb[#self.dataTb])
- table.remove(self.dataTb)
- end
- return unpack(popTb)
- end
- function Stack:Peek()
- return self.dataTb[#self.dataTb]
- end
- function Stack:List()
- for i = #self.dataTb, 1, -1 do
- logOrange(i, self.dataTb[i].name, self.dataTb[i].logicTbl.rank)
- end
- end
- function Stack:Count()
- return #self.dataTb
- end
- function Stack:IsEmpty()
- return #self.dataTb == 0
- end
|