Skip to content

Instantly share code, notes, and snippets.

@rorysaur
Created February 21, 2015 22:38
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rorysaur/d546a3ade03c2d2dd7c3 to your computer and use it in GitHub Desktop.
Save rorysaur/d546a3ade03c2d2dd7c3 to your computer and use it in GitHub Desktop.
typescript stack
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