Exemplo n.º 1
0
        //Method Called on Merging a linkined list
        public Node MergeLists(SinglyLinkedList inputList)
        {
            // setting the head to a variable of runner
            Node runnerOne = head;
            //setting the second head to
            Node runnerTwo = inputList.head;
            int  limit     = inputList.ListLength();

            if (ListLength() < inputList.ListLength())
            {
                limit = ListLength();
            }
            for (int i = 0; i < limit; i++)
            {
                InsertAfter(runnerOne.Value, runnerTwo.Value);
                if (i == limit)
                {
                    break;
                }
                runnerOne = runnerOne.Next.Next;
                runnerTwo = runnerTwo.Next;
            }
            return(head);
        }