public static void fillLinkedList(LinkedList s_list) { s_list.Clear(); s_list.AddInTail(new Node(12)); s_list.AddInTail(new Node(55)); s_list.AddInTail(new Node(55)); s_list.AddInTail(new Node(33)); s_list.AddInTail(new Node(55)); s_list.AddInTail(new Node(128)); s_list.AddInTail(new Node(55)); s_list.AddInTail(new Node(56)); Console.WriteLine("начальный список"); print(s_list); }
//суммирование списков одной длины static LinkedList AdditionList(LinkedList sList1, LinkedList SList2) { LinkedList sListSumm = new LinkedList(); if (sList1.Count() == SList2.Count() && sList1.Count() > 0) { Node node1 = sList1.head; Node node2 = SList2.head; while (node1 != null) { sListSumm.AddInTail(new Node(node1.value + node2.value)); node1 = node1.next; node2 = node2.next; } } return(sListSumm); }
public static LinkedList CreateFromUnite(LinkedList first, LinkedList second) { if (first.count != second.count || first.count == 0 || second.count == 0) { return(null); } LinkedList uniteList = new LinkedList(); Node firstNode = first.head; Node secondNode = second.head; while (firstNode != null && secondNode != null) { uniteList.AddInTail(new Node(firstNode.value + secondNode.value)); firstNode = firstNode.next; secondNode = secondNode.next; } return(uniteList); }
public void TestInitialize() { // nodes initializing userNode0 = new Node(42); userNode1 = new Node(13); userNode2 = new Node(7); userNode3 = new Node(24); userNode4 = new Node(0); userNode5 = new Node(0); userNode6 = new Node(12); userNode7 = new Node(2); userNode8 = new Node(7); userNode9 = new Node(7); userNode10 = new Node(7); userNode11 = new Node(12); userNode12 = new Node(21); userNode13 = new Node(37); userNode14 = new Node(84); userNode15 = new Node(11); // userList with 10 nodes creating userList = new LinkedList(); userList.AddInTail(userNode1); userList.AddInTail(userNode2); userList.AddInTail(userNode3); userList.AddInTail(userNode4); userList.AddInTail(userNode5); userList.AddInTail(userNode6); userList.AddInTail(userNode7); userList.AddInTail(userNode8); userList.AddInTail(userNode9); userList.AddInTail(userNode10); // userListOne with 1 node creating userListOne = new LinkedList(); userListOne.AddInTail(userNode0); // userListEmpty with no nodes creating userListEmpty = new LinkedList(); // finding the heads and tails of created LinkedLists userListHeadBefore = userList.head; userListTailBefore = userList.tail; userListOneHeadBefore = userListOne.head; userListOneTailBefore = userListOne.tail; userListEmptyHeadBefore = userListEmpty.head; userListEmptyTailBefore = userListEmpty.tail; // checking the heads and tails of created LinkedLists Assert.AreEqual(userNode1, userListHeadBefore); Assert.AreEqual(userNode10, userListTailBefore); Assert.AreEqual(userNode0, userListOneHeadBefore); Assert.AreEqual(userNode0, userListOneTailBefore); Assert.AreEqual(null, userListEmptyHeadBefore); Assert.AreEqual(null, userListEmptyTailBefore); }