Instantly share code, notes, and snippets.

Embed
What would you like to do?
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