예제 #1
0
        public static void Write(LinkedList2 list)
        {
            var node = list.head;

            while (node != null)
            {
                Console.Write("{0} ", node.value);
                node = node.next;
            }
            Console.WriteLine();
        }
예제 #2
0
        public void TestInitialize()
        {
            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);
            userNode16 = new Node(8);
            userNode17 = new Node(10);

            userList = new LinkedList2();
            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);
            Assert.AreEqual(userNode1, userList.head);
            Assert.AreEqual(userNode2, userList.head.next);
            Assert.AreEqual(null, userList.head.prev);
            Assert.AreEqual(userNode10, userList.tail);
            Assert.AreEqual(null, userList.tail.next);
            Assert.AreEqual(userNode9, userList.tail.prev);

            userListOne = new LinkedList2();
            userListOne.AddInTail(userNode0);
            Assert.AreEqual(userNode0, userListOne.head);
            Assert.AreEqual(null, userListOne.head.next);
            Assert.AreEqual(null, userListOne.head.prev);
            Assert.AreEqual(userNode0, userListOne.tail);
            Assert.AreEqual(null, userListOne.tail.next);
            Assert.AreEqual(null, userListOne.tail.prev);

            userListEmpty = new LinkedList2();
            Assert.AreEqual(null, userListEmpty.head);
            Assert.AreEqual(null, userListEmpty.tail);
        }
예제 #3
0
        public static LinkedList2 GenerateLinkedListElements(LinkedList2 list, int count)
        {
            var n = new Random();

            while (count > 0)
            {
                list.AddInTail(new Node(n.Next(255)));
                count--;
            }
            return(list);
        }