-
Notifications
You must be signed in to change notification settings - Fork 3
Stack
lnx00 edited this page Aug 27, 2023
·
2 revisions
Implementation of the stack data structure.
-
.new()
Creates a new Stack instance.
-
:push(item)
Pushes the item onto the stack. -
:pop()
Pops and returns the top of the stack. -
:peek()
Returns the top of the stack. -
:empty()
Returns whether the stack is empty. -
:clear()
Clears the stack. -
:size()
Returns the size of the stack.
local myStack = Stack.new()
myStack.push("World")
myStack.push("Hello")
print(myStack:pop()) -- Prints "Hello"
print(myStack:pop()) -- Prints "World"