Exemplo n.º 1
0
 public void AddSorted(int data)
 {
     if (headNode == null)
     {
         headNode = new Node(data);
     }
     else if (data < headNode.data)
     {
         AddToBeginning(data);
     }
     else
     {
         headNode.AddSorted(data);
     }
 }
Exemplo n.º 2
0
 public void AddSorted(int data)
 {
     if (next == null)
     {
         next = new Node(data);
     }
     else if (data < next.data)
     {
         Node temp = new Node(data);
         temp.next = this.next;
         this.next = temp;
     }
     else
     {
         next.AddSorted(data); // pass responsability to the next node in the list until adding sucessfuly!
     }
 }
Exemplo n.º 3
0
 public void AddSorted(int data)
 {
     if (next == null)
     {
         next = new Node(data);
     }
     else if (data < next.data)
     {
         Node temp = new Node(data);
         temp.next = this.next;
         this.next = temp;
     }
     else
     {
         next.AddSorted(data);
     }
 }