3. Given the following TypeScript code for inserting at the end of a doubly linked list, what will be the printed list after insertion?
class Node {
data: number;
next: Node | null = null;
prev: Node | null = null;
constructor(data: number) { this.data = data; }
}
class DoublyLinkedList {
head: Node | null = null;
insertAtEnd(data: number) {
const newNode = new Node(data);
if (!this.head) {
this.head = newNode;
return;
}
let temp = this.head;
while (temp.next) {
temp = temp.next;
}
temp.next = newNode;
newNode.prev = temp;
}
printList() {
let temp = this.head;
let result = '';
while (temp) {
result += temp.data + ' -> ';
temp = temp.next;
}
result += 'null';
console.log(result);
}
}
const dll = new DoublyLinkedList();
dll.insertAtEnd(10);
dll.insertAtEnd(20);
dll.insertAtEnd(30);
dll.printList();