예제 #1
0
        public void MergeTwoListsTest()
        {
            var q           = new ArrayQ();
            var linkedList1 = new ListNode(1)
            {
                next = new ListNode(2)
            };

            linkedList1.next.next = new ListNode(4);

            var linkedList2 = new ListNode(1)
            {
                next = new ListNode(3)
            };

            linkedList2.next.next = new ListNode(4);

            var mergedList = q.MergeTwoLists(linkedList1, linkedList2);

            Assert.AreEqual("1 1 2 3 4 4", GetLinkedListItems(mergedList));

            linkedList1 = null;
            linkedList2 = new ListNode(0)
            {
                next = null
            };
            mergedList = q.MergeTwoLists(linkedList1, linkedList2);
            Assert.AreEqual("0", GetLinkedListItems(mergedList));

            linkedList2 = null;
            linkedList1 = new ListNode(0)
            {
                next = null
            };
            mergedList = q.MergeTwoLists(linkedList1, linkedList2);
            Assert.AreEqual("0", GetLinkedListItems(mergedList));
        }