Beispiel #1
0
 public static Node24 removeDuplicates(Node24 head)
 {
     //Write your code here
     lstNumbers.Add(head.data);
     checkDuplicate(head, head.next);
     return(head);
 }
Beispiel #2
0
        public static void display(Node24 head)
        {
            Node24 start = head;

            while (start != null)
            {
                Console.Write(start.data + " ");
                start = start.next;
            }
        }
Beispiel #3
0
        public static void Main(String[] args)
        {
            Node24 head = null;
            int    T    = Int32.Parse(Console.ReadLine());

            while (T-- > 0)
            {
                int data = Int32.Parse(Console.ReadLine());
                head = insert(head, data);
            }
            head = removeDuplicates(head);
            display(head);
        }
Beispiel #4
0
 public static void checkDuplicate(Node24 prior, Node24 node)
 {
     if (node == null)
     {
         return;
     }
     if (lstNumbers.Contains(node.data))
     {
         prior.next = node.next;
         checkDuplicate(prior, prior.next);
     }
     else
     {
         lstNumbers.Add(node.data);
         checkDuplicate(node, node.next);
     }
 }
Beispiel #5
0
        public static Node24 insert(Node24 head, int data)
        {
            Node24 p = new Node24(data);


            if (head == null)
            {
                head = p;
            }
            else if (head.next == null)
            {
                head.next = p;
            }
            else
            {
                Node24 start = head;
                while (start.next != null)
                {
                    start = start.next;
                }
                start.next = p;
            }
            return(head);
        }
Beispiel #6
0
 public Node24(int d)
 {
     data = d;
     next = null;
 }