Exemple #1
0
        public static void Do()
        {
            Tree root = new TreeNode
            {
                Left = new TreeNode
                {
                    Left = new TreeLeaf {
                        Value = 1
                    },
                    Right = new TreeLeaf {
                        Value = 2
                    }
                },
                Right = new TreeLeaf {
                    Value = 3
                }
            };

            SumTreeVisitor visitor = new SumTreeVisitor();

            root.Accept(visitor);

            Console.WriteLine("Suma wartości na drzewie to {0}", visitor.Sum);
            Console.ReadLine();
        }
Exemple #2
0
        public void bigTreeHeightTest()
        {
            //        r
            //      /   \
            //     a     b
            //    /  \
            //   c    d
            //  /  \ 
            // e    f
            // | \
            // g  h

            Tree root = new TreeNode()                          // r
            {
                left = new TreeNode()                           // a
                {
                    left = new TreeNode()                       // c
                    {
                        left = new TreeNode()                   // e
                        {
                            left  = new TreeLeaf(),             // g
                            right = new TreeLeaf()
                        },                                      // h
                        right = new TreeLeaf()
                    },                                          // f
                    right = new TreeLeaf()
                },                                              // d
                right = new TreeLeaf()                          // b
            };
            HeightVisitor visitor = new HeightVisitor();

            root.Accept(visitor);
            Assert.AreEqual(4, visitor.height);
        }
Exemple #3
0
 public QueryFilter Build(TreeNode treeNode)
 {
     if (treeNode != null)
     {
         this.isQueryFilterValid = true;
         treeNode.Accept(this);
         if (this.isQueryFilterValid && this.CurrentLevelFilters.Count > 0)
         {
             return(this.CurrentLevelFilters[0]);
         }
     }
     return(null);
 }
Exemple #4
0
        public void heightTest()
        {
            //      r
            //    l    r
            //  ll lr
            Tree root = new TreeNode()
            {
                left = new TreeNode()
                {
                    left  = new TreeLeaf(),
                    right = new TreeLeaf()
                },
                right = new TreeLeaf()
            };

            HeightVisitor visitor = new HeightVisitor();

            root.Accept(visitor);

            Assert.AreEqual(2, visitor.height);
        }