public static void display(Node head) { Node start = head; while (start != null) { Console.Write(start.data + " "); start = start.next; } }
public static Node insert(Node head, int data) { Node p = new Node(data); if (head == null) head = p; else if (head.next == null) head.next = p; else { Node start = head; while (start.next != null) start = start.next; start.next = p; } return head; }
public static Node removeDuplicates(Node head) { Node start = head; while (start != null) { if (start.next != null && start.data == start.next.data) { Node nextNext = start.next.next; start.next = nextNext; } else { start = start.next; } } return head; }
public Node(int d) { data = d; next = null; }