// 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); } } }
// 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); } }
public NewTree() { root = null; }
public NodeStructure(int item) { data = item; left = right = null; }