#include <iostream>
using namespace std;
bool judgeBST(int list[], int n)
{
if(list == NULL || n < 0)
{
return false;
}
int root = list[n - 1];
int i = 0;
int j = 0;
while(list[i] < root)
{
i++;
}
j = i;
for(int t = j; t < n - 1; t++)
{
if(list[t] < root)
return false;
}
return judgeBST(list, i) && judgeBST(&list[j], n - j - 1);
};
int main()
{
int list[] = {5, 7, 6, 9, 11, 10, 8};
bool isBST = judgeBST(list, 7);
}
判断整数序列是不是二元查找树的后序遍历结果
最新推荐文章于 2021-03-16 17:18:32 发布