Skip to content

Instantly share code, notes, and snippets.

@pragmaticlogic
Last active August 29, 2015 14:07
Show Gist options
  • Select an option

  • Save pragmaticlogic/d8f6a1f2db5785679dad to your computer and use it in GitHub Desktop.

Select an option

Save pragmaticlogic/d8f6a1f2db5785679dad to your computer and use it in GitHub Desktop.
TowerStack
public class TowerStack<T:_Comparable> : Stack<T> {
override func push(key:T) {
let current:Node<T>! = top
if (top == nil) {
super.push(key)
}
else if (top.key! > key) {
super.push(key)
} else {
NSException(name: "Tower Collapse", reason: "A larger disk is placed on top of a smaller disk", userInfo: nil).raise()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment