コード例 #1
0
ファイル: NewTree.cs プロジェクト: Bhattaha/AIS-Traning
        // 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);
                }
            }
        }
コード例 #2
0
ファイル: NewTree.cs プロジェクト: Bhattaha/AIS-Traning
 //
 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);
     }
 }
コード例 #3
0
ファイル: NewTree.cs プロジェクト: Bhattaha/AIS-Traning
 public NewTree()
 {
     root = null;
 }
コード例 #4
0
ファイル: NodeStructure.cs プロジェクト: Bhattaha/AIS-Traning
 public NodeStructure(int item)
 {
     data = item;
     left = right = null;
 }