Beispiel #1
0
        public bool Contains(TreeNode node, IGateSwitch data)
        {
            if (node == null)
            {
                return(false);
            }

            if (node.Data == data)
            {
                return(true);
            }

            Console.WriteLine(node.Data);
            if (Contains(node.Left, data))
            {
                return(true);
            }
            else
            {
                return(Contains(node.Right, data));
            }

            //if (node.Data > data)
            //{
            //    Console.WriteLine(node.Data);
            //    return Contains(node.Left, data);
            //}
            //else
            //{
            //    Console.WriteLine(node.Data);
            //    return Contains(node.Right, data);
            //}
        }
Beispiel #2
0
 public bool IsLeftSubTreeLessOrEqual(TreeNode root, IGateSwitch data)
 {
     if (root == null)
     {
         return(true);
     }
     Console.WriteLine("left {0} {1} {2}", root.Data, data, root.Data.Id <= data.Id);
     return(root.Data.Id <= data.Id && IsLeftSubTreeLessOrEqual(root.Left, data) && IsLeftSubTreeLessOrEqual(root.Right, data));
 }
Beispiel #3
0
        public bool IsRightSubTreeGreater(TreeNode root, IGateSwitch data)
        {
            if (root == null)
            {
                return(true);
            }

            Console.WriteLine("right {0} {1} {2}", root.Data, data, root.Data.Id > data.Id);
            return(root.Data.Id > data.Id && IsRightSubTreeGreater(root.Left, data) && IsRightSubTreeGreater(root.Right, data));
        }
 public TreeNode(IGateSwitch data, int level)
 {
     this.Data  = data;
     this.Level = level;
 }
 public TreeNode(IGateSwitch data)
 {
     this.Data  = data;
     this.Level = 0;
 }