Module: lib-tde.datastructure.queue

Lua Implementation of a queue

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

local queue = require("lib-tde.datastructure.queue")
local list = queue()
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 queue

Time complexity:

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

Info:

  • Copyright: 2020 Tom Meyers
  • Author: Tom Meyers

Static module functions

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


Static module functions

lib-tde.datastrucuture.queue () -> table
Create a new Queue

Returns:

    table An empty queue

Usage:

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

Parameters:

  • value object The value to put into the queue

Usage:

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

Usage:

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

Usage:

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

Usage:

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