Queue<T>

Summary

System.Queue<T> provides a FIFO (first in, first out) data structure.

Description

System.Queue<T> provides a FIFO (first in, first out) data structure.

Examples

Instantiation
1
2
3
import System;
 
auto queue = new System.Queue<int>();
Initialization with data
1
2
3
import System;
 
auto queue = new System.Queue<int>([ 1, 2, 3 ]);
Comparison with System.Stack<T>
1
2
3
4
5
6
import System;
 
auto queue = new System.Queue<int>([ 1, 2, 3 ]);
auto stack = new System.Stack<int>([ 1, 2, 3 ]);
Console.log(queue.pop()); // 1
Console.log(stack.pop()); // 3

Methods

  • clear

    Clears the queue by removing all elements from the queue.

  • isEmpty

    Checks if the queue is empty.

  • length

    Returns the number of elements in the queue.

  • peek

    Returns the most earliest element pushed without removing it.

  • pop

    Returns and removes the earliest element added to the queue.

  • push

    Adds an element to the collection.

  • Queue (Constructor)

    Constructs a System.Queue<T> object.

  • toString

    Returns a string representation of the queue.

Share

HTML | BBCode | Direct Link