Queue

public struct Queue<T>

A queue is a First-In-First-Out (FIFO) collection, the first element added to the queue will be the first one to be removed.

The enqueue and dequeue operations run in amortized constant time.

Conforms to Sequence, ExpressibleByArrayLiteral, CustomStringConvertible.

  • Constructs an empty queue.

    Declaration

    Swift

    public init()
  • Constructs a queue from a sequence, such as an array. The elements will be enqueued from first to last.

    Declaration

    Swift

    public init<S: Sequence>(_ elements: S) where S.Iterator.Element == T
  • Number of elements stored in the queue.

    Declaration

    Swift

    public var count : Int
  • Returns true if and only if count == 0.

    Declaration

    Swift

    public var isEmpty: Bool
  • The front element in the queue, or nil if the queue is empty.

    Declaration

    Swift

    public var first: T?
  • Inserts an element into the back of the queue.

    Declaration

    Swift

    public mutating func enqueue(_ element: T)
  • Retrieves and removes the front element of the queue.

    Declaration

    Swift

    public mutating func dequeue() -> T

    Return Value

    The front element.

  • Removes all the elements from the queue, and by default clears the underlying storage buffer.

    Declaration

    Swift

    public mutating func removeAll(keepingCapacity keep: Bool = false)
  • Provides for-in loop functionality. Generates elements in FIFO order.

    Declaration

    Swift

    public func makeIterator() -> AnyIterator<T>

    Return Value

    A generator over the elements.

  • Constructs a queue using an array literal. The elements will be enqueued from first to last. let queue: Queue<Int> = [1,2,3]

    Declaration

    Swift

    public init(arrayLiteral elements: T...)
  • A string containing a suitable textual representation of the queue.

    Declaration

    Swift

    public var description: String