public void TestAppendToNullList() { ///test appends to null list int testNum = 33; LiList testList = new LiList(); testList.Append(testNum); int expectedValue = 33; Assert.Equal(expectedValue, testList.Head.Value); }
public void TestAppendDoesNotChangeHead() { ///test append does not insert the new appended node at the head int testNum1 = 3; int testNum2 = 13; int testNum3 = 23; LiList testList = new LiList(); testList.Insert(testNum1); testList.Insert(testNum2); testList.Append(testNum3); int expectedNalue = 13; Assert.Equal(expectedNalue, testList.Head.Value); }
public void TestAppendToEnd() { ///test appends method at to end node head int testNum1 = 7; int testNum2 = 17; int testNum3 = 77; LiList testList = new LiList(); testList.Insert(testNum1); testList.Insert(testNum2); testList.Append(testNum3); int expectedValue = 77; Assert.Equal(expectedValue, testList.Head.Next.Next.Value); }
/// <summary> /// Zip two linked lists together /// </summary> /// <param name="lOne">list one</param> /// <param name="lTwo">list two</param> /// <returns>zipped list</returns> public static LiList Merge(LiList lOne, LiList lTwo) { lOne.Current = lOne.Head; int counterOne = 0; int counterTwo = 0; while (lOne.Current.Next != null) /// interrate through linked list to get count, start at one in order to equate for positioning { lOne.Current = lOne.Current.Next; counterOne++; } lTwo.Current = lTwo.Head; while (lTwo.Current.Next != null) /// interrate through linked list to get count, start at one in order to equate for positioning { lTwo.Current = lTwo.Current.Next; counterTwo++; } int newCount = counterOne + counterTwo; /// length of both lists for new list Node C1 = lOne.Head; ///reference holder 1 Node C2 = lTwo.Head; /// reference holder 2 while (newCount > 1) { if (lTwo.Current != null) { lOne.InsertAfter(C1.Value, C2.Value); C1 = C1.Next.Next; C2 = C2.Next; lOne.Print(); } else { lOne.Append(C2.Value); C2 = C2.Next; lOne.Print(); } newCount--; } return(lOne); }