Stack
public struct Stack<Element>
extension Stack: Collection
extension Stack: CustomDebugStringConvertible where Element: CustomDebugStringConvertible
A basic stack type implementing the LIFO principle - only the last inserted element can be accessed and removed.
-
Creates an empty
Stack.Declaration
Swift
public init() -
The number of elements in this stack.
Declaration
Swift
public var count: Int { get } -
Pushes (appends) an element onto the stack.
Declaration
Swift
public mutating func push(_ element: Element)Parameters
elementThe element to push onto the stack.
-
Removes and returns the last element of the stack.
Declaration
Swift
@discardableResult public mutating func pop() -> Element?Return Value
The last element of the stack if the stack is not empty; otherwise, nil.
-
Returns the last element of the stack if the stack is not empty; otherwise, nil.
Declaration
Swift
public func peek() -> Element? -
Check whether the sequence contains an element that satisfies the given predicate.
Declaration
Swift
public func contains(where predicate: (Element) -> Bool) -> BoolParameters
predicateA closure that takes an element of the sequence and returns whether it represents a match.
Return Value
trueif the sequence contains an element that satisfiespredicate. -
Modify the last element.
Declaration
Swift
public mutating func modifyLast(by modifier: (inout Element) -> Void)Parameters
modifierA function to be applied to the last element to modify the same in place.
-
Declaration
Swift
public var startIndex: Int { get } -
Declaration
Swift
public var endIndex: Int { get } -
Declaration
Swift
public subscript(position: Int) -> Element { get } -
Declaration
Swift
public func index(after index: Int) -> Int
-
Declaration
Swift
public var debugDescription: String { get }
View on GitHub
Install in Dash