Exemple #1
0
        public void Case1()
        {
            var l1 = new MergeTwoLists.ListNode(1)
            {
                next = new MergeTwoLists.ListNode(2)
                {
                    next = new MergeTwoLists.ListNode(4)
                }
            };

            var l2 = new MergeTwoLists.ListNode(1)
            {
                next = new MergeTwoLists.ListNode(3)
                {
                    next = new MergeTwoLists.ListNode(4)
                }
            };
            var results = new MergeTwoLists().Go(l1, l2);

            var expected = new List <int> {
                1, 1, 2, 3, 4, 4
            };

            CollectionAssert.AreEqual(expected, results.GetFull());
        }
        private MergeTwoLists.ListNode CreateLink(List <int> values)
        {
            var root    = new MergeTwoLists.ListNode(values[0]);
            var current = root;

            for (int i = 1; i < values.Count; i++, current = current.next)
            {
                current.next = new MergeTwoLists.ListNode(values[i]);
            }
            return(root);
        }
        private bool AreEqual(MergeTwoLists.ListNode l, List <int> values)
        {
            if (l == null)
            {
                return(false);
            }

            for (int i = 0; i < values.Count && l != null; i++, l = l.next)
            {
                if (l.val != values[i])
                {
                    return(false);
                }
            }
            return(true);
        }