Last active
August 29, 2015 14:07
-
-
Save pragmaticlogic/d8f6a1f2db5785679dad to your computer and use it in GitHub Desktop.
TowerStack
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
| 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