3. Consider the following JavaScript code for a dequeue using a doubly linked list:
class Node {
constructor(value) {
this.value = value;
this.next = null;
this.prev = null;
}
}
class Dequeue {
constructor() {
this.head = null;
this.tail = null;
}
addFront(value) {
const newNode = new Node(value);
if (!this.head) {
this.head = this.tail = newNode;
} else {
newNode.next = this.head;
this.head.prev = newNode;
this.head = newNode;
}
}
addRear(value) {
const newNode = new Node(value);
if (!this.tail) {
this.head = this.tail = newNode;
} else {
this.tail.next = newNode;
newNode.prev = this.tail;
this.tail = newNode;
}
}
removeFront() {
if (!this.head) return null;
const val = this.head.value;
this.head = this.head.next;
if (this.head) this.head.prev = null;
else this.tail = null;
return val;
}
}
const dq = new Dequeue();
dq.addRear(10);
dq.addFront(20);
dq.addRear(30);
const removed = dq.removeFront();
console.log(removed);
console.log(dq.head.value + ' -> ' + dq.tail.value);
What will be the output?