Stack - lnx00/Lmaobox-Library GitHub Wiki

Stack

Implementation of the stack data structure.

Functions

  • .new() Creates a new Stack instance.

Methods

  • :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.

Example

local myStack = Stack.new()
myStack.push("World")
myStack.push("Hello")

print(myStack:pop()) -- Prints "Hello"
print(myStack:pop()) -- Prints "World"