Created
January 3, 2017 00:31
-
-
Save ChenCodes/62f16864d8c7ff4fa60df930cb76e06e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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