Skip to content

Instantly share code, notes, and snippets.

View Vectormike's full-sized avatar
🏠
Working from home

Victor Jonah Vectormike

🏠
Working from home
View GitHub Profile
class Node {
constructor(data, next = null){
this.data = data;
this.next = next
}
}
dequeue() {
// Since it's FIFO, we point to the data in front
let node = this.front;
// Check if queue is empty
if(!isEmpty()) {
// move to the next data, and make it the first item in the queue
this.front = this.front.next;
}
class Queue {
constructor() {
this.head = null;
this.back = null;
}
// Let us always check if the queue is empty before we do anything
isEmpty() {
return !this.head;
}
class Node {
constructor(value) {
this.value = value;
this.next = null;
}
}
if rear is equal to than 0
print 'Queue is full'
return true
else
return false
if front is greater than 0
print 'Queue is empty'
return true
else
return false
return queue[front]
if queue is empty
print 'Queue is empty'
end
data = Queue[head]
head = head++
return data
if queue is full
print 'Queue is full'
end
rear = rear++
Queue[rear] = data
return
// Returns the element at the top of the stack
this.peek = function () {
if(this.isEmpty() === true) {
console.log('Stack is empty');
return;
}
return this.data[this.count - 1];
};