Stack
public struct Stack<T>
Stack A stack is like an array but with limited functionality. You can only push to add a new element to the top of the stack, pop to remove the element from the top, and peek at the top element without popping it off. A stack gives you a LIFO or last-in first-out order. The element you pushed last is the first one to come off with the next pop. Push and pop are O(1) operations.
## Usage
var myStack = Stack(array: [])
myStack.push(10)
myStack.push(3)
myStack.push(57)
myStack.pop() // 57
myStack.pop() // 3
-
Indicates the number of values contained within the
array
object.Declaration
Swift
public var count: Int { get }
-
Indicates whether or not the
array
object contains zero (0) values.Declaration
Swift
public var isEmpty: Bool { get }
-
Pushes an item to the top of the stack.
Declaration
Swift
public mutating func push(_ element: T)
Parameters
element
The item being pushed.
-
Removes and returns the item at the top of the stack.
Declaration
Swift
public mutating func pop() -> T?
Return Value
The item at the top of the stack.
-
Returns the item at the top of the stack. This is otherwise known as
peek
.Declaration
Swift
public var top: T? { get }
-
Undocumented
Declaration
Swift
public mutating func clear()
-
Indicates whether or not the
array
object contains zero (0) values.Declaration
Swift
public var isNotEmpty: Bool { get }