コード例 #1
0
        public void RemoveTests()
        {
            // Add three elements
            Node <int> head = new Node <int>(1);

            head.AppendToTail(2);
            head.AppendToTail(3);
            ListHelpers.ValidateLinkedListContent(head, 1, 2, 3);

            // Remove the middle one
            head = head.DeleteNode(head, 2);
            ListHelpers.ValidateLinkedListContent(head, 1, 3);

            // Remove the first one
            head = head.DeleteNode(head, 1);
            ListHelpers.ValidateLinkedListContent(head, 3);

            // Remove non-existent head
            head = head.DeleteNode(head, 4);
            ListHelpers.ValidateLinkedListContent(head, 3);
        }
コード例 #2
0
        public void BasicTest()
        {
            // Add an element
            Node <int> head = new Node <int>(1);

            ListHelpers.ValidateLinkedListContent(head, 1);

            // Add two more elements
            head.AppendToTail(2);
            head.AppendToTail(3);
            ListHelpers.ValidateLinkedListContent(head, 1, 2, 3);

            // Remove the middle element
            head = head.DeleteNode(head, 2);
            ListHelpers.ValidateLinkedListContent(head, 1, 3);
        }