Esempio n. 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);
        }
Esempio n. 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);
     }
 }
Esempio n. 3
0
 static bool CheckBinaryTree(NodeTree root)
 {
     return(isBinaryTree(root));
 }
Esempio n. 4
0
 public NodeTree(int data)
 {
     this.Data = data;
     Left      = Right = null;
 }