Skip to content

Instantly share code, notes, and snippets.

@davidinga
Last active May 29, 2019 18:44
Show Gist options
  • Save davidinga/7282413a8724930a367398900cc21613 to your computer and use it in GitHub Desktop.
Save davidinga/7282413a8724930a367398900cc21613 to your computer and use it in GitHub Desktop.
Stack with Array implementation
struct Stack<Element> {
fileprivate var array = [Element]()
public var isEmpty: Bool {
return array.isEmpty
}
public var count: Int {
return array.count
}
public func peek() -> Element? {
return array.last
}
public mutating func push(_ element: Element) {
array.append(element)
}
public mutating func pop() -> Element? {
return array.popLast()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment