Last active
October 10, 2016 18:34
-
-
Save markd2/134ac081cb88defa8bbea11d01892955 to your computer and use it in GitHub Desktop.
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
| import Foundation | |
| class Stack<T> { | |
| var storage = [T]() | |
| func push(_ thing: T) { | |
| storage.append(thing) | |
| } | |
| func pop() -> T { | |
| // declaring it a programmer error if trying to pop an empty stack | |
| return storage.popLast()! | |
| } | |
| func isEmpty() -> Bool { | |
| return storage.count == 0 | |
| } | |
| } | |
| let intStack = Stack<Int>() | |
| intStack.push(5) | |
| intStack.push(10) | |
| intStack.pop() | |
| intStack.pop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment