文章
67
粉丝
35
获赞
1
访问
12.1k
1.递归对每个结点和其左右结点比较,若左节点小于它右节点大于它则返回true,否则返回false,遇到-1即空结点则返回,若是二叉搜索树则返回true
2.
bool detect(ElemType sqbiTNode[],int nodeIndex){
int leftIndex=2*nodeIndex+1,rightIndex=2*nodeIndex+2;
bool left,right;
if(sqbiTNode[leftIndex]>sqbiTNode[nodeIndex]){
left=false;
}else if(!(sqbiTNode[leftIndex]>0)){
left=true;
}else{
left=detect(eqbiTNode,leftIndex);
}
if(!left) return false;
if(sqbiTNode[rightIndex]<sqbiTNode[nodeIndex]){
right=false;
}else if(!(sqbiTNode[rightIndex]>0)){
right=true;
}else{
right=detect(eqbiTNode,rightIndex);
}
if(right) return true;
else return false;
}
bool main(SqBiTree *T){
return detect(T->sqbiTNode,0);
}
登录后发布评论
暂无评论,来抢沙发