经典指数          
原因
1830
浏览数
0
收藏数
 

已知二叉树中的结点类型用BinTreeNode表示,被定义为:     struct  BinTreeNode { ElemType  data;   BinTreeNode * leftChild, * rightChild;}; 其中data为结点数据域,leftChild 和 rightChild 分别是指向左、右子女结点的指针域。下面函数的功能是返回二叉树BT中值为x的结点所在的层数,请在划有橫线的地方填写合适的语句。 int  NodeLeve1( BinTreeNode * BT , ElemType  &x ) {int c1,c2;     if ( BT= = NULL ) return  -1;   //空树的层数为-1   else  if (BT->data= = x ) return 0 ; //根结点的层数为0 else { c1= NodeLeve1 (BT->leftChild , x ) ;//向左子树中查找值为x结点 if (c1>=0)                             ; c2=                                     ;//向右子树中查找值为x结点 if (c2>=0)                             ; else  return -2;    //在树中不存在x结点时返回-2 }}

     举报   纠错  
 
切换
暂时还没有答案,欢迎分享你的解答 . . .
撰写答案
扫描后移动端查看本题