示例#1
0
        static bool isBinaryTree(NodeTree root)
        {
            // traverse the tree in inorder fashion and
            // keep track of prev node
            if (root != null)
            {
                if (!isBinaryTree(root.Left))
                {
                    return(false);
                }

                // Allows only distinct valued nodes
                if (prev != null &&
                    root.Data <= prev.Data)
                {
                    return(false);
                }

                prev = root;

                return(isBinaryTree(root.Right));
            }

            return(true);
        }
示例#2
0
 static NodeTree Insert(NodeTree root, int data)
 {
     if (root == null)
     {
         return(new NodeTree(data));
     }
     else
     {
         NodeTree cur;
         if (data <= root.Data)
         {
             cur       = Insert(root.Left, data);
             root.Left = cur;
         }
         else
         {
             cur        = Insert(root.Right, data);
             root.Right = cur;
         }
         return(root);
     }
 }
示例#3
0
 static bool CheckBinaryTree(NodeTree root)
 {
     return(isBinaryTree(root));
 }
示例#4
0
 public NodeTree(int data)
 {
     this.Data = data;
     Left      = Right = null;
 }