Created
February 21, 2015 22:38
-
-
Save rorysaur/d546a3ade03c2d2dd7c3 to your computer and use it in GitHub Desktop.
typescript stack
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
interface Collection { | |
push(value: any): void; | |
pop(): any; | |
peek(): any; | |
isEmpty(): boolean; | |
} | |
class Stack implements Collection { | |
top: any | |
constructor() { | |
this.top = null; | |
} | |
push(value: any) { | |
this.top = { | |
value: value, | |
next: this.top | |
}; | |
} | |
pop() { | |
var value = this.top.value; | |
this.top = this.top.next; | |
return value; | |
} | |
peek() { | |
return this.top.value; | |
} | |
isEmpty() { | |
return this.top === null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment