示例#1
0
文件: Program.cs 项目: myu404/IntBST
        public static int Sum(IntTreeNode clientRoot)
        {
            if (clientRoot == null)
            {
                return(0);
            }

            return(clientRoot.data + Sum(clientRoot.left) + Sum(clientRoot.right));
        }
示例#2
0
文件: Program.cs 项目: myu404/IntBST
        public static int Height(IntTreeNode clientRoot)
        {
            if (clientRoot == null)
            {
                return(0);
            }

            return(1 + Math.Max(Height(clientRoot.left), Height(clientRoot.right)));
        }
示例#3
0
文件: Program.cs 项目: myu404/IntBST
        public static string ToStringInOrder(IntTreeNode clientRoot)
        {
            string str = "";

            if (clientRoot != null)
            {
                str += ToStringInOrder(clientRoot.left) + " " + clientRoot.data + " " + ToStringInOrder(clientRoot.right) + " ";
            }
            return(str);
        }
示例#4
0
文件: Program.cs 项目: myu404/IntBST
 public static bool ExistsST(IntTreeNode clientRoot, int value)
 {
     if (clientRoot == null)
     {
         return(false);
     }
     if (clientRoot.data == value)
     {
         return(true);
     }
     return(Exists(clientRoot.left, value) || Exists(clientRoot.right, value));
 }
示例#5
0
文件: Program.cs 项目: myu404/IntBST
        private IntTreeNode Add(IntTreeNode root, int value)
        {
            if (root == null)
            {
                root = new IntTreeNode(value);
            }

            else if (value <= root.data)
            {
                root.left = Add(root.left, value);
            }

            else
            {
                root.right = Add(root.right, value);
            }

            return(root);
        }
示例#6
0
文件: Program.cs 项目: myu404/IntBST
 // Instance Methods
 public void Add(int value)
 {
     root = Add(root, value);
 }
示例#7
0
文件: Program.cs 项目: myu404/IntBST
 // Constructor
 public IntSearchTree()
 {
     root = null;
 }
示例#8
0
文件: Program.cs 项目: myu404/IntBST
 public IntTreeNode(int data, IntTreeNode left, IntTreeNode right)
 {
     this.data  = data;
     this.left  = left;
     this.right = right;
 }