Skip to content

Instantly share code, notes, and snippets.

@markd2
Last active October 10, 2016 18:34
Show Gist options
  • Select an option

  • Save markd2/134ac081cb88defa8bbea11d01892955 to your computer and use it in GitHub Desktop.

Select an option

Save markd2/134ac081cb88defa8bbea11d01892955 to your computer and use it in GitHub Desktop.
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