public void TestMergeListNodes() { // 1 => 2 => 3 => 4 => 5 var a = new ListNode(5, null); var b = new ListNode(4, a); var c = new ListNode(3, b); var d = new ListNode(2, c); var e = new ListNode(1, d); // 3 => 3 => 3 => 4 => 5 var a2 = new ListNode(5, null); var b2 = new ListNode(4, a2); var c2 = new ListNode(3, b2); var d2 = new ListNode(3, c2); var e2 = new ListNode(3, d2); // 8 => 9 var d3 = new ListNode(9, null); var e3 = new ListNode(8, d3); // 1 => 1 var d4 = new ListNode(1, null); var e4 = new ListNode(1, d4); var expectedResult = "11123333445589"; var result = ListNodeMethod.PrintListNode(ListNodeMethod.MergeListNodes(new System.Collections.Generic.List <ListNode> { e, e2, e3, e4 })); Assert.AreEqual(expectedResult, result); }
public void TestReverseListNode() { // 3 => 2 => 1 var a = new ListNode(1, null); var b = new ListNode(2, a); var c = new ListNode(3, b); var result = ListNodeMethod.PrintListNode(ListNodeMethod.ReverseListNode(c)); Assert.AreEqual("123", result); }
public void TestReverseListNodeWithIndex_OutOfBoundary() { // 5 => 4 => 3 => 2 => 1 var a = new ListNode(1, null); var b = new ListNode(2, a); var c = new ListNode(3, b); var d = new ListNode(4, c); var e = new ListNode(5, d); var result = ListNodeMethod.PrintListNode(ListNodeMethod.ReverseListNodeWithIndex(e, 3, 8)); Assert.AreEqual("54123", result); }
public void TestReverseListNodeWithIndex_SameStartAndEnd() { // 5 => 4 => 3 => 2 => 1 var a = new ListNode(1, null); var b = new ListNode(2, a); var c = new ListNode(3, b); var d = new ListNode(4, c); var e = new ListNode(5, d); var result = ListNodeMethod.PrintListNode(ListNodeMethod.ReverseListNodeWithIndex(e, 3, 3)); Assert.AreEqual("54321", result); }
public void TestPartitionListNode_AllBigger() { // 5 => 4 => 3 => 2 => 6 var a = new ListNode(6, null); var b = new ListNode(2, a); var c = new ListNode(3, b); var d = new ListNode(4, c); var e = new ListNode(5, d); var result = ListNodeMethod.PrintListNode(ListNodeMethod.PartitionListNode(e, 1)); Assert.AreEqual("54326", result); }
public void TestPartitionListNode() { // 5 => 4 => 3 => 2 => 1 var a = new ListNode(1, null); var b = new ListNode(2, a); var c = new ListNode(3, b); var d = new ListNode(4, c); var e = new ListNode(5, d); var result = ListNodeMethod.PrintListNode(ListNodeMethod.PartitionListNode(e, 3)); Assert.AreEqual("21543", result); }
public void TestDeepCloneRandomListNode() { var a = new RandomListNode(1, null, null); var b = new RandomListNode(2, a, null); var c = new RandomListNode(3, b, a); var d = new RandomListNode(4, c, null); d.random = d; var e = new RandomListNode(5, d, b); a.random = d; var expectedResult = ListNodeMethod.PrintListNode(e); var result = ListNodeMethod.PrintListNode(ListNodeMethod.DeepCloneRandomListNode(e)); Assert.AreEqual(expectedResult, result); c.val = 9; Assert.AreEqual(expectedResult, result); }