コード例 #1
0
        public void MergeWith(LinkedListAgain otherList)
        {
            Node myCurrent    = head;
            Node otherCurrent = otherList.head;

            Node newHead = null;
            Node newTail = null;

            //pick one from each list and add both per iteration
            while (myCurrent != null || otherCurrent != null)
            {
                if (myCurrent != null)
                {
                    InsertIntoList(ref newHead, ref newTail, myCurrent);
                    myCurrent = myCurrent.Next;
                }

                if (otherCurrent != null)
                {
                    InsertIntoList(ref newHead, ref newTail, otherCurrent);
                    otherCurrent = otherCurrent.Next;
                }
            }

            this.head = newHead;
            this.tail = newTail;
        }
コード例 #2
0
        public void MergeWith(LinkedListAgain otherList)
        {
            Node myCurrent = head;
            Node otherCurrent = otherList.head;

            Node newHead = null;
            Node newTail = null;

            //pick one from each list and add both per iteration
            while (myCurrent != null || otherCurrent != null)
            {
                if (myCurrent != null)
                {
                    InsertIntoList(ref newHead, ref newTail, myCurrent);
                    myCurrent = myCurrent.Next;
                }

                if (otherCurrent != null)
                {
                    InsertIntoList(ref newHead, ref newTail, otherCurrent);
                    otherCurrent = otherCurrent.Next;
                }
            }

            this.head = newHead;
            this.tail = newTail;
        }
コード例 #3
0
        public static void Test()
        {
            LinkedListAgain list = new LinkedListAgain();

            list.Add(2);
            list.Add(1);
            list.Add(4);
            list.Add(3);
            list.Add(5);

            //LinkedListAgain list2 = new LinkedListAgain();

            //list2.Add(2);
            //list2.Add(4);
            //list2.Add(6);
            //list2.Add(8);

            //list.MergeWith(list2);

            list.Print();
            list.SwapElements();
            list.Print();
            list.Add(6);
            list.Print();
        }
コード例 #4
0
        public static void Test()
        {
            LinkedListAgain list = new LinkedListAgain();

            list.Add(2);
            list.Add(1);
            list.Add(4);
            list.Add(3);
            list.Add(5);

            //LinkedListAgain list2 = new LinkedListAgain();

            //list2.Add(2);
            //list2.Add(4);
            //list2.Add(6);
            //list2.Add(8);

            //list.MergeWith(list2);

            list.Print();
            list.SwapElements();
            list.Print();
            list.Add(6);
            list.Print();
        }