"Queue" (Data Structure)

"Queue"

represents a queue of expressions.

Details

  • A queue is a collection of elements that supports first-in, first-out insertion and removal:
  • CreateDataStructure["Queue"]create a new empty "Queue"
    Typed[x,"Queue"]give x the type "Queue"
  • For a data structure of type "Queue", the following operations can be used:
  • ds["Copy"]return a copy of dstime: O(n)
    ds["DropAll"]drop all the elements from dstime: O(n)
    ds["EmptyQ"]True, if ds is emptytime: O(1)
    ds["Length"]number of elements in dstime: O(1)
    ds["Peek"]last element in dstime: O(1)
    ds["Pop"]remove the first element of dstime: O(1)
    ds["Push",x]add x to the end of dstime: O(1)
    ds["Visualization"]return a visualization of dstime: O(n)
  • The following functions are also supported:
  • dsi===dsjTrue, if dsi equals dsj
    FullForm[ds]full form of ds
    Information[ds]information about ds
    InputForm[ds]input form of ds
    Normal[ds]convert ds to a normal expression

Examples

open allclose all

Basic Examples  (2)

A new "Queue" can be created with CreateDataStructure:

ds is initially empty:

Add an element to the end of ds:

ds is no longer empty:

It has one element:

Add another element and peek. This shows the first element:

Remove the first element:

Return an expression version of ds:

It is fast to put elements into a queue:

A visualization of the data structure can be generated:

Scope  (1)

Information  (1)

A new "Queue" can be created with CreateDataStructure:

Information about the data structure ds: