赞
踩
/*
24:> BST的后序遍历
*/
bool judge(int ar[], int len)
{
if (ar == NULL || len <= 0)
return false;
int root = ar[len - 1];
int i = 0;
for (; i < len-1; ++i)
if(ar[i]>root)
break;
int j = i;
for (; j < len - 1; ++j)
if (ar[j] < root)
return false;
bool left = true;
if (i > 0)
left = judge(ar, i);
bool right = true;
if (i < len - 1)
right = judge(ar + i, len - i-1);
return left && right;
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。