Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local stack = {new = function()
- local toReturn = {list = {}, size = 0}
- toReturn = {list = toReturn.list, size = toReturn.size ,push = function(item)
- local toSave = toReturn.list[1]
- for i = 1, toReturn.size do
- local temp = toReturn.list[i+1]
- toReturn.list[i+1] = toSave
- toSave = temp
- end
- toReturn.list[1] = item
- toReturn.size = toReturn.size +1
- end,
- pop = function()
- if(toReturn.size ~= 0) then
- local r = toReturn.list[1]
- for i = 1, toReturn.size do
- toReturn.list[i] = toReturn.list[i+1]
- end
- toReturn.size = toReturn.size -1
- return r
- end
- end
- }
- return toReturn
- end
- }
- return stack
Advertisement
Add Comment
Please, Sign In to add comment