public void Test1() { Intersect.ListNode first1 = this.MakeList(new int[] { 1, 3, 7, 10 }); Intersect.ListNode first2 = this.MakeList(new int[] { 5, 4, 3, 2 }); Assert.AreEqual(-1, Intersect.Solve(first1, first2)); }
public void Test3() { Intersect.ListNode first1 = this.MakeList(new int[] { 1 }); Intersect.ListNode first2 = this.MakeList(new int[] { 5, 2, 3, 11, 15 }); Assert.AreEqual(-1, Intersect.Solve(first1, first2)); }
private Intersect.ListNode MakeList(int[] list) { if (list.Length == 0) { return(null); } Intersect.ListNode firstNode, currentNode; firstNode = new Intersect.ListNode() { Value = list[0] }; currentNode = firstNode; for (int i = 1; i < list.Length; i++) { currentNode.Next = new Intersect.ListNode() { Value = list[1] }; currentNode = currentNode.Next; } return(firstNode); }
private void MergeLists(Intersect.ListNode first1, Intersect.ListNode first2) { while (first1.Next != null) { first1 = first1.Next; } first1.Next = first2; }
public void Test7() { Intersect.ListNode first = this.MakeList(new int[] { 5, 2, 3, 11, 15 }); Intersect.ListNode crossFirst = this.MakeList(new int[] { 11, 23, 43 }); this.MergeLists(first, crossFirst); Assert.AreEqual(5, Intersect.Solve(first, crossFirst)); Assert.AreEqual(0, Intersect.Solve(crossFirst, first)); }
public void Test6() { Intersect.ListNode first1 = this.MakeList(new int[] { 1 }); Intersect.ListNode first2 = this.MakeList(new int[] { 5, 2, 3, 11, 15 }); Intersect.ListNode crossFirst = this.MakeList(new int[] { 11, 23, 43 }); this.MergeLists(first1, crossFirst); this.MergeLists(first2, crossFirst); Assert.AreEqual(1, Intersect.Solve(first1, first2)); }
public void Test4() { Intersect.ListNode first1 = this.MakeList(new int[] { 1, 3, 7, 10 }); Intersect.ListNode first2 = this.MakeList(new int[] { 5, 4, 3, 2 }); Intersect.ListNode crossFirst = this.MakeList(new int[] { 11, 23, 43 }); this.MergeLists(first1, crossFirst); this.MergeLists(first2, crossFirst); Assert.AreEqual(4, Intersect.Solve(first1, first2)); }