Created
January 29, 2019 16:49
-
-
Save thexande/377dd5660ffaf35b062852fe81251372 to your computer and use it in GitHub Desktop.
Swift Stack Implementation
This file contains hidden or 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
| struct Stack<T> { | |
| private var stack: [T] = [] | |
| mutating func push(_ item: T) { | |
| stack.append(item) | |
| } | |
| mutating func pop() -> T { | |
| return stack.removeLast() | |
| } | |
| func peek() -> T? { | |
| return stack.last | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment