Beispiel #1
0
    static void Main()
    {
        Linkedlist l1 = new Linkedlist();

        l1.addLastWithTail(1);
        l1.addLastWithTail(5);
        l1.addLastWithTail(7);
        l1.addLastWithTail(9);
        l1.changenext(ref l1.head);
        l1.printList();
    }
    public void sortedMerge(Node a, Node b)
    {
        Node       current1 = a;
        Node       current2 = b;
        Linkedlist l3       = new Linkedlist();

        if (a == null)
        {
            l3.head = b;
            return;
        }
        if (b == null)
        {
            l3.head = a;
            return;
        }
        while (current1 != null && current2 != null)
        {
            if (current1.data <= current2.data)
            {
                l3.addLastWithTail(current1.data);
                current1 = current1.next;
            }
            else
            {
                l3.addLastWithTail(current2.data);
                current2 = current2.next;
            }
        }
        if (current1 == null)
        {
            l3.tail.next = current2;
        }
        if (current2 == null)
        {
            l3.tail.next = current1;
        }
        l3.printList();
    }
 public void sortedMerge(Node a,Node b)
 {
     Node current1=a;
     Node current2=b;
     Linkedlist l3=new Linkedlist();
     if(a==null)
     {
         l3.head=b;
         return;
     }
     if(b==null)
     {
         l3.head=a;
         return;
     }
     while(current1!=null &&current2!=null)
     {
         if(current1.data<=current2.data)
         {
             l3.addLastWithTail(current1.data);
             current1=current1.next;
         }
         else
         {
             l3.addLastWithTail(current2.data);
             current2=current2.next;
         }
     }
     if(current1==null)
     {
         l3.tail.next=current2;
     }
     if(current2==null)
     {
         l3.tail.next=current1;
     }
     l3.printList();
 }