Created
November 8, 2021 21:42
-
-
Save captain-yossarian/2a4cf3c7d1a72544a888f0ad5e5ade6d to your computer and use it in GitHub Desktop.
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
class Queue<T> { | |
private items: T[] | |
constructor() { | |
this.items = new Array<T>(); | |
} | |
enqueue(element: T) { | |
this.items.push(element); | |
} | |
dequeue() { | |
return this.items.shift(); | |
} | |
peek() { | |
return this.items[0] | |
} | |
isEmpty() { | |
return this.items.length === 0 | |
} | |
} | |
class Stack<T> { | |
private items: T[] | |
constructor() { | |
this.items = new Array() | |
} | |
push(item: T) { | |
return this.items.push(item) | |
} | |
pop() { | |
return this.items.pop() | |
} | |
peek() { | |
return this.items[this.items.length - 1] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment