public void ThrowExceptionIfBothLinkedListsAreNull() { Linklist LL1 = new Linklist(); Linklist LL2 = new Linklist(); Assert.Throws <Exception>(() => Program.LLMerge(LL1, LL2)); }
public void TestReturnSecondLinkedListIfFirstLinkedListIsNull() { Linklist LL2 = new Linklist(); LL2.Append(1); LL2.Append(3); LL2.Append(2); Linklist LL1 = new Linklist(); Program.LLMerge(LL1, LL2); int[] actual = new int[3] { LL2.Head.Value, LL2.Head.Next.Value, LL2.Head.Next.Next.Value, }; int[] expected = new int[3] { 1, 3, 2 }; Assert.Equal(expected, actual); }
public void TestMergeOfLinkedListsOfEqualLengths() { Linklist List1 = new Linklist(); List1.Insert(1); List1.Insert(3); List1.Insert(2); Linklist List2 = new Linklist(); List2.Insert(5); List2.Insert(9); List2.Insert(4); Linklist MergedList = new Linklist(); MergedList.Insert(1); MergedList.Insert(5); MergedList.Insert(3); MergedList.Insert(9); MergedList.Insert(2); MergedList.Insert(4); Assert.Equal(MergedList); }
public void CanAppendToAnEmptyLinkedList(int value) { Linklist ll = new Linklist(); ll.Append(value); Assert.Equal(value, ll.Head.Value); }
public void CanInsertNewNodeToLinkedListAsHead() { Linklist ll = new Linklist(); ll.Insert(10); Assert.Equal(10, ll.Head.Value); }
public void CanInsertNewNodeToLinkedListAsHead(int expected) { Linklist ll = new Linklist(); ll.Insert(expected); Assert.Equal(expected, ll.Head.Value); }
public void TestProperlyZipsLinkedLists() { Linklist LL1 = new Linklist(); LL1.Append(1); LL1.Append(3); LL1.Append(2); Linklist LL2 = new Linklist(); LL2.Append(5); LL2.Append(9); LL2.Append(4); Linklist merge = Program.LLMerge(LL1, LL2); int[] actual = new int[6] { LL1.Head.Value, LL1.Head.Next.Value, LL1.Head.Next.Next.Value, LL1.Head.Next.Next.Next.Value, LL1.Head.Next.Next.Next.Next.Value, LL1.Head.Next.Next.Next.Next.Next.Value }; int[] expected = new int[3] { 1, 3, 2 }; Assert.Equal(expected, actual); }
static void Main(string[] args) { Console.WriteLine("Hello World!"); Linklist list1 = new Linklist(); Linklist list2 = new Linklist(); LLMerge(list1, list2); }
public void CanInsertNewNodeAsHeadInLLThatAlreadyHasNodes() { Linklist 11 = new Linklist(); 11.Insert(10); 11.Insert(20); Assert.Equal(20, 11.HeadValue); }
public void CanInsertNewNodeAsHeadInLLThatAlreadyHasNodes(int expected) { Linklist ll = new Linklist(); ll.Insert(20); ll.Insert(expected); Assert.Equal(expected, ll.Head.Value); }
public void CanInsertNewNodeAsHeadInLLThatAlreadyHasNodes() { Linklist ll = new Linklist(); ll.Insert(10); ll.Insert(20); Assert.Equal(20, ll.Head.Value); }
public void ThrowsAnErrorIfParamIsGreatherThanLinkedList() { Linklist ll = new Linklist(); ll.Append(23); ll.Append(232); ll.Append(2367); Assert.Throws <Exception>(() => ll.KthFromEnd(6)); }
public void CanReturnTrueIfValueInLinkedList(int value1, bool expected) { Linklist ll = new Linklist(); ll.Insert(value1); bool actual = ll.Includes(value1); Assert.Equal(actual, expected); }
/// <summary> /// Returns a 'zipped' linked list from two linked lists /// </summary> /// <param name="LL1">first linked list</param> /// <param name="LL2">second linked list</param> /// <returns></returns> public static Linklist LLMerge(Linklist LL1, Linklist LL2) { //throw exception if both linked lists are null if (LL1.Head == null && LL2.Head == null) { throw new Exception("Both linked lists are null"); } //Return other linked list if one linked list is null if (LL1.Head == null || LL2.Head == null) { return(LL1.Head == null ? LL2 : LL1); } //store both heads in a variable Node curr_A = LL1.Head; Node curr_B = LL2.Head; //traverse both trees, if neither is null while (curr_A.Next != null || curr_B.Next != null) { /*if first linked list is not null * store a reference it's next * point current to other linked list head */ if (curr_A.Next != null) { Node temp_A = curr_A.Next; curr_A.Next = curr_B; /* if second linked list is not null * store a reference to it's next * point current for second linked list to reference of first linked list * move both current forward for next iteration */ if (curr_B.Next != null) { Node temp_B = curr_B.Next; curr_B.Next = temp_A; curr_B = temp_B; curr_A = temp_A; } //if there is no next for second linked list, have it point to current of first linked list else { curr_B.Next = temp_A; } } //if current for first linked list is null, point it to current of second linked list if (curr_A.Next == null) { curr_A.Next = curr_B; } } //return the zipped linked list return(LL1); }
public void CanInsertANodeBeforeWithOnlyOneNodeInLinkedList(int value) { Linklist ll = new Linklist(); ll.Insert(23); ll.InsertBefore(23, value); int actual = ll.Head.Value; int expected = value; Assert.Equal(actual, expected); }
public virtual Linklist ToLiquidLinklist(StorefrontModel.MenuLinkList linkList, Storefront.Model.WorkContext workContext, IStorefrontUrlBuilder urlBuilder) { var result = new Linklist(); result.Id = linkList.Id; result.Handle = linkList.Name.Handelize(); result.Links = linkList.MenuLinks.Select(ml => ToLiquidLink(ml, workContext, urlBuilder)).ToList(); result.Title = linkList.Name; return(result); }
public static Linklist ToShopifyModel(this StorefrontModel.MenuLinkList storefrontModel, Storefront.Model.WorkContext workContext, IStorefrontUrlBuilder urlBuilder) { var shopifyModel = new Linklist(); shopifyModel.Handle = storefrontModel.Name; shopifyModel.Id = storefrontModel.Id; shopifyModel.Links = storefrontModel.MenuLinks.Select(ml => ml.ToShopfiyModel(workContext, urlBuilder)).ToList(); shopifyModel.Title = storefrontModel.Name; return(shopifyModel); }
public static Linklist ToShopifyModel(this StorefrontModel.MenuLinkList storefrontModel) { var shopifyModel = new Linklist(); shopifyModel.Handle = storefrontModel.Name; shopifyModel.Id = storefrontModel.Id; shopifyModel.Links = storefrontModel.MenuLinks.Select(ml => ml.ToShopfiyModel()).ToList(); shopifyModel.Title = storefrontModel.Name; return(shopifyModel); }
public void CanInsertANodeAfterWithOnlyOneNodeInLinkedList(int value) { Linklist ll = new Linklist(); ll.Append(23); ll.InsertAfter(23, value); int actual = ll.Tail.Value; int expected = value; Assert.Equal(actual, expected); }
public void ReturnsAllNodeValueInStringFormat() { Linklist ll = new Linklist(); ll.Insert(3); ll.Insert(7); ll.Insert(9); string actual = ll.ToString(); string expected = $"{{{ll.Head.Value}}}-->{{{ll.Head.Next.Value}}}-->{{{ll.Head.Next.Next.Value}}}-->NULL"; Assert.Equal(actual, expected); }
public void CanFindLastNodeValueInLL() { Linklist 11 = new Linklist(); 11.Insert(10); 11.Insert(20); 11.Insert(30); 11.Insert(42); bool exists = 11.Includes(10); Assert.True(exists); }
public void CanFindHeadValueSucessfullyinLL() { Linklist 11 = new Linklist(); 11.Insert(10); 11.Insert(20); 11.Insert(30); 11.Insert(42); bool exists = 11.Includes(42); Assert.True(exists); }
public void CannotFindNodewithValueinLL() { Linklist 11 = new Linklist(); 11.Insert(10); 11.Insert(20); 11.Insert(30); 11.Insert(42); bool exists = 11.Includes(32); Assert.False(exists); }
public void CanChangePointers() { Linklist LL1 = new Linklist(); LL1.Append(1); Linklist LL2 = new Linklist(); LL2.Append(2); Linklist merge = Program.LLMerge(LL1, LL2); }
public void CanAppendToALinkedListWithNodes(int value) { Linklist ll = new Linklist(); ll.Insert(20); ll.Insert(22); ll.Insert(24); ll.Append(value); int expected = ll.Tail.Value; Assert.Equal(value, expected); }
public void IfParameterIsZeroReturnTailValue() { Linklist ll = new Linklist(); ll.Append(23); ll.Append(232); ll.Append(2367); int actual = ll.KthFromEnd(0); int expected = ll.Tail.Value; Assert.Equal(expected, actual); }
public virtual Linklist ToLiquidLinklist(StorefrontModel.MenuLinkList linkList, Storefront.Model.WorkContext workContext, IStorefrontUrlBuilder urlBuilder) { var result = new Linklist(); result.InjectFrom <StorefrontModel.Common.NullableAndEnumValueInjecter>(linkList); result.Handle = linkList.Name; result.Links = linkList.MenuLinks.Select(ml => ToLiquidLink(ml, workContext, urlBuilder)).ToList(); result.Title = linkList.Name; return(result); }
/// <summary> /// test to see whether a node with a given value can be inserted into a linked list after a node with a given value /// </summary> public void CanInsertAfterInLinkedList() { Linklist ll = new Linklist(); ll.Insert(10); ll.Insert(20); ll.Insert(30); ll.InsertBefore(10, 42); int testValue = 10; int newValue = 42; Assert.Equal(42, ll.Current.Next.Value); }
public void CanFindNodeWithValueInLL() { Linklist ll = new Linklist(); ll.Insert(10); ll.Insert(20); ll.Insert(30); ll.Insert(42); bool exists = ll.Includes(30); Assert.True(exists); }
public void CanFindHeadValueSuccessfullyInLL() { Linklist ll = new Linklist(); ll.Insert(10); ll.Insert(20); ll.Insert(30); ll.Insert(42); bool exists = ll.Includes(42); Assert.True(exists); }