面试题24:二叉搜索树的后续遍历序列
来源:互联网 发布:mac adobe id安装失败 编辑:程序博客网 时间:2024/04/29 05:07
#include <deque>#include <stdio.h>#include <iostream>#include <stdlib.h>using namespace std;bool VerifySequenceOfBST(int *sequence, int length){ if (sequence == NULL || length <= 0 ) { return false; } int root = sequence[length-1] ; int i = 0; for(; i < length -1; i++ ) { if(sequence[i] > root ) { break; } } int j = i; for(;j < length -1; j++) { if(sequence[j] < root) { return false; } } bool left = true; if(i > 0) { left = VerifySequenceOfBST(sequence, i); } bool right = true; if(i < length -1) right = VerifySequenceOfBST(sequence+i, length - i - 1 ); return (left && right);}int main(){ int a[7] = {5,7,6,9,11,10,8}; int a1[4]= {7,4,6,5}; bool result =false; result = VerifySequenceOfBST(&a1[0], 4); cout<<result<<endl; return 0;}
0 0
- 面试题24:二叉搜索树的后续遍历序列
- 【剑指offer】面试题24:二叉搜索树的后续前序遍历序列
- 剑指offer面试题24:二叉搜索树的后续遍历序列 Java实现
- 【剑指Offer】面试题24:二叉搜索树的后续遍历序列
- 剑指offer面试题 二叉搜索树的后续遍历序列
- 剑指offer 面试题24 判断二叉搜索树后续遍历序列
- 二叉搜索树的后续遍历序列
- 二叉搜索树的后续遍历序列
- 二叉搜索树的后续遍历序列
- 二叉搜索树的后续遍历序列
- 二叉搜索树的后续遍历序列
- 搜索二叉树的后续遍历序列
- 二叉搜索树的后续遍历序列
- 二叉搜索树的后续遍历序列
- 判断二叉搜索树的后续遍历序列
- [剑指Offer]二叉搜索树的后续遍历序列
- 剑指Offer之 - 二叉搜索树的后续遍历序列
- 剑指Offer--二叉搜索树的后续遍历序列
- 31. Next Permutation
- ubuntu12.04的64位系统安装的注意事项
- 判断字符串中每个字符出现的次数
- c::求两个数的最大公约数和最小公倍数
- CSP考试 2016年12月第2题 工资计算 C++实现
- 面试题24:二叉搜索树的后续遍历序列
- 练习
- linux时间相关命令
- Grunt常用插件及示例说明
- 50 leetcode - Maximum Product Subarray
- ubuntu12.04的64位系统编译android4.0的一些错误的解决方法
- 《TCP/IP详解》读书笔记
- 2241: [SDOI2011]打地鼠
- 产品经理如何推动项目落地