#include<iostream>
using namespace std;
typedef struct Binode
{
int data;
struct Binode *lchild,*rchild;
}Binode,*Bitree;
bool BitreeVerify(int str[],int length)
{
if(str==NULL||length<=0)
return false;
int i,j,temp;
temp=str[length-1];
for(i=0;i<length-1;i++)
{
if(str[i]>temp)
break;
}
j=i;
for(;j<length-1;j++)
{
if(str[j]<temp)
false;
}
bool left=true;
if(i>0)
left=BitreeVerify(str,i);
bool right=true;
if(j<length-1)
right=BitreeVerify(str+i,length-i-1);
return (left&&right);
}
int main()
{
int num1[]={5,7,6,9,11,10,8};
cout<<BitreeVerify(num1,7)<<endl;
system("pause");
return 0;
}
二叉搜索树的后序判断
最新推荐文章于 2023-03-19 11:29:26 发布