Exemplo n.º 1
0
        // Calculate  the height of a tree
        public virtual int Height(NodeStructure root)

        {
            if (root == null)
            {
                return(0);
            }
            else
            {
                //check the height of left hand side
                int lheight = Height(root.left);
                //check the height of right hand side
                int rheight = Height(root.right);

                // compare the left hand side height and right hand side height and return the height which is highest
                if (lheight > rheight)
                {
                    return(lheight);
                }
                else
                {
                    return(rheight);
                }
            }
        }
Exemplo n.º 2
0
 //
 public virtual void Traversal(NodeStructure root, int level)
 {
     if (root == null)
     {
         return;
     }
     if (level == 1)
     {
         Console.Write(root.data + " ");
     }
     else if (level > 1)
     {
         Traversal(root.left, level - 1);
         Traversal(root.right, level - 1);
     }
 }
Exemplo n.º 3
0
 public NewTree()
 {
     root = null;
 }
Exemplo n.º 4
0
 public NodeStructure(int item)
 {
     data = item;
     left = right = null;
 }