Stack
public struct Stack<Element>
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() -
True if the stack has no elements. False otherwise.
Declaration
Swift
public var isEmpty: Bool { get } -
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?
-
Declaration
Swift
public var debugDescription: String { get }
View on GitHub
Install in Dash
Stack Structure Reference