Skip to content

Instantly share code, notes, and snippets.

@ChenCodes
Created January 3, 2017 00:31
Show Gist options
  • Save ChenCodes/62f16864d8c7ff4fa60df930cb76e06e to your computer and use it in GitHub Desktop.
Save ChenCodes/62f16864d8c7ff4fa60df930cb76e06e to your computer and use it in GitHub Desktop.
public struct Stack<T> {
fileprivate var array = [T]()
public var isEmpty: Bool {
return array.isEmpty
}
public var count: Int {
return array.count
}
public mutating func push(_ element: T) {
array.append(element)
}
public mutating func pop() -> T? {
return array.popLast()
}
public var top: T? {
return array.last
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment