Esempio n. 1
0
 public static void PrintProps <T>([NotNull] this ArrayBinaryTree <T> thisValue)
 {
     Console.WriteLine();
     Console.WriteLine($"{Yellow("Dimensions:")} {Underline(thisValue.Count.ToString())} x {Underline(thisValue.GetHeight().ToString())}.");
     Console.WriteLine($"{Yellow("Valid:")} {thisValue.Validate().ToYesNo()}");
     Console.WriteLine($"{Yellow("LeftMost:")} {thisValue.LeftMost()} {Yellow("RightMost:")} {thisValue.RightMost()}");
 }
Esempio n. 2
0
        public void AddNodes_Array()
        {
            int[] output;
            var   binaryTree = new ArrayBinaryTree();

            binaryTree.AddNode(50);
            binaryTree.AddNode(30);
            binaryTree.AddNode(70);
            binaryTree.AddNode(20);
            binaryTree.AddNode(40);
            binaryTree.AddNode(60);
            binaryTree.AddNode(80);
            //binaryTree.AddNode(52);
            //binaryTree.AddNode(70);

            void print() =>
            output = binaryTree.Read(TreeTraversalTypes.Preorder);

            print();

            binaryTree.DeleteNode(20);

            print();

            binaryTree.DeleteNode(30);

            print();

            binaryTree.DeleteNode(50);

            print();
        }
Esempio n. 3
0
        public void ArrayTreeIsExpandedOnDemand()
        {
            var sut = new ArrayBinaryTree <int>(1);

            sut.Root(1);
            sut.SetLeft(1, 2);
            sut.SetRight(1, 3);
            sut.SetLeft(2, 4);
            sut.SetRight(2, 5);

            Assert.Equal(2, sut.GetTree()[2]);
            Assert.Equal(3, sut.GetTree()[3]);
            Assert.Equal(4, sut.GetTree()[4]);
            Assert.Equal(5, sut.GetTree()[5]);
        }
Esempio n. 4
0
 public static void Print <T>([NotNull] this ArrayBinaryTree <T> thisValue)
 {
     Console.WriteLine();
     thisValue.WriteTo(Console.Out);
 }
Esempio n. 5
0
 public static void PrintWithProps <T>([NotNull] this ArrayBinaryTree <T> thisValue)
 {
     PrintProps(thisValue);
     thisValue.Print();
 }