예제 #1
0
 public virtual void levelWiseTravel(NodeStructure root, int level)  // Print nodes at the given level
 {
     if (root == null)
     {
         return;
     }
     if (level == 1)
     {
         Console.Write(root.data + " ");
     }
     else if (level > 1)
     {
         levelWiseTravel(root.left, level - 1);
         levelWiseTravel(root.right, level - 1);
     }
 }
예제 #2
0
        public virtual int height(NodeStructure root) // Compute the "height" of a tree

        {
            if (root == null)
            {
                return(0);
            }
            else
            {
                int lheight = height(root.left);
                int rheight = height(root.right);

                if (lheight > rheight)
                {
                    return(lheight + 1);
                }
                else
                {
                    return(rheight + 1);
                }
            }
        }
예제 #3
0
        public NodeStructure root;              // Root of the Binary Tree

        public BFS_RB()
        {
            root = null;
        }
예제 #4
0
 public NodeStructure(int item)
 {
     data = item;
     left = right = null;
 }