3. Given the following code snippet, what will be the printed output after inserting 30 at the end of the doubly linked list?
class Node {
public int data;
public Node next, prev;
public Node(int d) { data = d; next = prev = null; }
}
class DoublyLinkedList {
public Node head;
public void InsertAtEnd(int data) {
Node newNode = new Node(data);
if (head == null) {
head = newNode;
return;
}
Node temp = head;
while (temp.next != null) {
temp = temp.next;
}
temp.next = newNode;
newNode.prev = temp;
}
public void PrintList() {
Node temp = head;
while (temp != null) {
Console.Write(temp.data + " -> ");
temp = temp.next;
}
Console.WriteLine("null");
}
}
DoublyLinkedList dll = new DoublyLinkedList();
dll.InsertAtEnd(10);
dll.InsertAtEnd(20);
dll.InsertAtEnd(30);
dll.PrintList();