Stackable

protocol Stackable

An interface for stack data structure needed by e.g. LampSort.

Based on an example from Stackoverflow.

See https://stackoverflow.com/questions/31462272/stack-implementation-in-swift

  • Type of elements to put into a stack.

    Declaration

    Swift

    associatedtype Element
  • To peek if stack has an element to pop.

    Declaration

    Swift

    func peek() -> Element?
  • Push new element on top of the stack.

    Declaration

    Swift

    mutating func push(_ element: Element)
  • Pop an element from the top of the stack.

    Declaration

    Swift

    @discardableResult
    mutating func pop() -> Element?