class Node{
constructor(value){
this.data = value;
this.next = null;
}
}
class Queue{
constructor(){
this.front = null;
this.rear = null;
this.length = 0;
}
enqueue(value)
{
let newNode = new Node(value);
if(this.rear==null)
{
this.rear = newNode;
this.front = newNode;
}
else
{
this.rear.next = newNode;
this.rear = newNode;
}
this.length++;
}
dequeue()
{
if(this.front==null)console.log('empty queue');
let temp = this.front;
this.front = temp.next;
let value = temp.data;
temp = null;
return value;
}
peek(){
return this.front.data;
}
isEmpty(){
return this.front==null;
}
}
let line = new Queue();
line.enqueue('Josh');
line.enqueue('Rahul');
line.enqueue('Swathi');
line.enqueue('Raja');
console.log(line.dequeue());
console.log(line.peek());