SwiftDataStructures Docs (35% documented)

SwiftDataStructures Reference Stack Struct Reference

Stack

Undocumented

  • Undocumented

  • Undocumented

  • Undocumented

  • Undocumented

  • Undocumented

  • Element order is [top, …, bottom], as if one were to iterate through the sequence in reverse, calling stack.push(element) on each element.

    Declaration

    Swift

    public init<S : SequenceType where S.Generator.Element == Element>(_ elements:S)
  • Adds an element to the top of the stack.

    Declaration

    Swift

    public mutating func push(elem: Element)

    Parameters

    elem

    The element to add.

  • Removes the top element from the stack and returns it.

    Declaration

    Swift

    public mutating func pop() -> Element?

    Return Value

    The removed element or nil if the stack is empty.

  • Returns the element at the specified index, or nil if the index was out of range.

    Declaration

    Swift

    public func at(index i:Int) -> Element?
  • Returns the index of the first element for which predicate returns true.

    Declaration

    Swift

    public func find(predicate: (Element) -> Bool) -> Index?
  • Inserts the provided element n positions from the top of the stack. The index must be >= startIndex and <= endIndex or a precondition will fail. Insert can therefore be used to append and prepend elements to the list (and, in fact, append and prepend simply call this function).

    Declaration

    Swift

    public mutating func insert(newElement:Element, atIndex i:Index.RawIndex)
  • Undocumented

  • Removes the element n positions from the top of the stack and returns it. index must be a valid index or a precondition assertion will fail.

    Declaration

    Swift

    public mutating func removeAtIndex(index:Index) -> Element

    Parameters

    index

    The index of the element to remove.

    Return Value

    The removed element.

  • Undocumented

  • This function is equivalent to pop(), except that it will fail if the stack is empty.

    Declaration

    Swift

    public mutating func removeTop() -> Element

    Return Value

    The removed element.