public void InsertAfterNodeByValue()
        {
            // 10 nodes
            userList.InsertAfter(userNode0, userNode11);
            Assert.AreEqual(10, userList.Count());
            Assert.AreEqual(userNode1, userList.head);
            Assert.AreEqual(userNode10, userList.tail);
            Assert.AreEqual(userNode2, userList.head.next);
            Assert.AreEqual(null, userList.tail.next);

            userList.InsertAfter(userNode6, userNode11);
            Assert.AreEqual(11, userList.Count());
            Assert.AreEqual(userNode1, userList.head);
            Assert.AreEqual(userNode10, userList.tail);
            Assert.AreEqual(userNode2, userList.head.next);
            Assert.AreEqual(null, userList.tail.next);

            userList.InsertAfter(userNode1, userNode12);
            Assert.AreEqual(12, userList.Count());
            Assert.AreEqual(userNode1, userList.head);
            Assert.AreEqual(userNode10, userList.tail);
            Assert.AreEqual(userNode12, userList.head.next);
            Assert.AreEqual(null, userList.tail.next);

            userList.InsertAfter(userNode10, userNode13);
            Assert.AreEqual(13, userList.Count());
            Assert.AreEqual(userNode1, userList.head);
            Assert.AreEqual(userNode13, userList.tail);
            Assert.AreEqual(userNode12, userList.head.next);
            Assert.AreEqual(null, userList.tail.next);

            // 1 node
            userListOne.InsertAfter(userNode3, userNode14);
            Assert.AreEqual(1, userListOne.Count());
            Assert.AreEqual(userNode0, userListOne.head);
            Assert.AreEqual(userNode0, userListOne.tail);
            Assert.AreEqual(null, userListOne.head.next);
            Assert.AreEqual(null, userListOne.tail.next);

            userListOne.InsertAfter(userNode0, userNode14);
            Assert.AreEqual(2, userListOne.Count());
            Assert.AreEqual(userNode0, userListOne.head);
            Assert.AreEqual(userNode14, userListOne.tail);
            Assert.AreEqual(userNode14, userListOne.head.next);
            Assert.AreEqual(null, userListOne.tail.next);

            // no nodes
            userListEmpty.InsertAfter(userNode10, userNode15);
            Assert.AreEqual(0, userListEmpty.Count());
            Assert.AreEqual(null, userListEmpty.head);
            Assert.AreEqual(null, userListEmpty.tail);

            userListEmpty.InsertAfter(null, userNode15);
            Assert.AreEqual(1, userListEmpty.Count());
            Assert.AreEqual(userNode15, userListEmpty.head);
            Assert.AreEqual(userNode15, userListEmpty.tail);
            Assert.AreEqual(null, userListEmpty.head.next);
            Assert.AreEqual(null, userListEmpty.tail.next);
        }
Exemplo n.º 2
0
        public static void test6(LinkedList s_list)
        {
            Console.WriteLine("6. метод вставки узла после заданного узла.");
            Console.WriteLine("вставляем 128 после узла со значением 33");
            Console.WriteLine("вставляем 48 после узла со значением 56");

            s_list.InsertAfter(s_list.Find(33), new Node(128));
            s_list.InsertAfter(s_list.Find(56), new Node(48));
            print(s_list);
        }