Skip to content

Instantly share code, notes, and snippets.

@captain-yossarian
Created November 8, 2021 21:42
Show Gist options
  • Save captain-yossarian/2a4cf3c7d1a72544a888f0ad5e5ade6d to your computer and use it in GitHub Desktop.
Save captain-yossarian/2a4cf3c7d1a72544a888f0ad5e5ade6d to your computer and use it in GitHub Desktop.
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