public void RecursiveInorderTraverseShouldVisitNodesInCorrectOrder()
 {
     //                      5
     //                  3
     //              2       4
     //          1
     DsalBinarySearchTree bst = new DsalBinarySearchTree();
     bst
         .AddItems(new List<int>() { 5, 3, 2, 1, 4 })
         .TraverseInorderRecursive()
         .Should().BeInAscendingOrder();
 }
 public void RecursivePreorderTraverseShouldVisitNodesInCorrectOrder()
 {
     //                      5
     //                  3
     //              2       4
     //          1
     DsalBinarySearchTree bst = new DsalBinarySearchTree();
     bst
         .AddItems(new List<int>() { 5, 3, 2, 1, 4 })
         .TraversePreorderRecursive()
         .Should().ContainInOrder(5, 3, 2, 1, 4);
 }
예제 #3
0
 public void RemoveNodeWithBothChildrenShouldSucceed()
 {
     //                      5
     //                  3
     //              2       4
     //          1
     DsalBinarySearchTree bst = new DsalBinarySearchTree();
     bst
         .AddItems(new List<int>() { 5, 3, 2, 1, 4 })
         .RemoveItem(3)
         .TraverseInorderRecursive()
         .Should().ContainInOrder(1, 2, 4, 5);
 }
 public void NonRecursivePreorderTraverseSShouldVisitNodesInCorrectOrder()
 {
     //                          3
     //                  1               5
     //                      2       4
     //
     //
     DsalBinarySearchTree bst = new DsalBinarySearchTree();
     bst
         .AddItems(new List<int>() { 3, 1, 2, 5, 4 })
         .TraversePreorderNonrecursive()
         .Should().ContainInOrder(3, 1, 2, 5, 4);
 }
예제 #5
0
 public void RemoveNodeWithBothChildrenAndRightChildHavingALeftSubtreeShouldSucceed()
 {
     //                      7
     //                  3
     //              2       6
     //          1       4
     //                      5
     DsalBinarySearchTree bst = new DsalBinarySearchTree();
     bst
         .AddItems(new List<int>() { 7, 3, 2, 6, 5, 1, 4 })
         .RemoveItem(3)
         .TraverseInorderRecursive()
         .Should().ContainInOrder(1, 2, 4, 5, 6, 7);
 }
예제 #6
0
        public void RemoveLeafNodeShouldSucceed()
        {
            //                      5
            //                  3
            //              2       4
            //          1

            DsalBinarySearchTree bst = new DsalBinarySearchTree();
            bst
                .AddItems(new List<int>() { 5, 3, 2, 1, 4 })
                .RemoveItem(1)
                .TraverseInorderRecursive()
                .Should().ContainInOrder(2, 3, 4, 5);
        }