Module: lib-tde.datastructure.stack

Lua Implementation of a stack

This module describes the api usage of a stack (LIFO) You can push items on the stack and pop them of the stack

local stack = require("lib-tde.datastructure.stack")
local list = stack()
list.push("first")
list.push("second")
list.pop() -- returns "first"
list.pop() -- returns "second"

list.next() -- returns the next element without removing it
list.size() -- returns the size of the stack

Time complexity:

  • Insert element O(1)
  • Remove element O(1)
  • List size O(1)

Class Hierarchy

  • lib-tde.datastructure.stack

Info:

  • Copyright: 2020 Tom Meyers
  • Author: Tom Meyers

Static module functions

lib-tde.datastrucuture.stack () -> table Create a new Stack
lib-tde.datastrucuture.stack.push (value) Add a new object to the stack
lib-tde.datastrucuture.stack.pop () Remove the next object in the stack and return it
lib-tde.datastrucuture.stack.next () This function is like @see pop however it doesn't remove the element from the stack
lib-tde.datastrucuture.stack.size () This function returns the amount of elements in the stack


Static module functions

lib-tde.datastrucuture.stack () -> table
Create a new Stack

Returns:

    table An empty stack

Usage:

    -- This will create a new stack
     lib-tde.datastrucuture.stack()
lib-tde.datastrucuture.stack.push (value)
Add a new object to the stack

Parameters:

  • value object The value to put into the stack

Usage:

    -- Add the string 'tde' to the stack
     stack.push("tde")
lib-tde.datastrucuture.stack.pop ()
Remove the next object in the stack and return it

Usage:

    -- Return 'tde' from the stack
     stack.pop()
lib-tde.datastrucuture.stack.next ()
This function is like @see pop however it doesn't remove the element from the stack

Usage:

    -- Return 'tde' from the stack
     stack.next()
lib-tde.datastrucuture.stack.size ()
This function returns the amount of elements in the stack

Usage:

    -- Return the size of the stack
     stack.size()
generated by LDoc 1.4.6 Build with 💜 By F0xedb Last updated 2021-05-21 03:30:15