3. What will be the output of the following C# code that creates a singly linked list with nodes 10, 20, 30 and prints the list?
public class Node {
public int data;
public Node next;
public Node(int d) { data = d; next = null; }
}
public class LinkedList {
public Node head;
public void Add(int data) {
Node newNode = new Node(data);
if (head == null) {
head = newNode;
} else {
Node temp = head;
while (temp.next != null) {
temp = temp.next;
}
temp.next = newNode;
}
}
public void PrintList() {
Node temp = head;
while (temp != null) {
Console.Write(temp.data + " -> ");
temp = temp.next;
}
Console.WriteLine("null");
}
}
class Program {
static void Main() {
LinkedList list = new LinkedList();
list.Add(10);
list.Add(20);
list.Add(30);
list.PrintList();
}
}