用递归做得,遇到的坑是用cygwin带的gcc编译,总是遇到各种莫名其妙的段溢出。。。珍爱生命,远离cygwin。。

#include "stdio.h"
#include "stdlib.h"
#include "string.h"//Definition for a binary tree node.struct TreeNode {char val;struct TreeNode *left;struct TreeNode *right;int index_a;};int index_t = 0,length=0;int make_tree(struct TreeNode *root,char *str){static int index_p = 0 , cou_t = 0;static char buf[10] ;int i=0 , rc;root = (struct TreeNode *)malloc(sizeof(struct TreeNode ));root->val = str[index_p];buf[cou_t] = root->val;printf("val %c\n", root->val);index_p++;cou_t++;if(root->val == '@'){printf("return @\n");return 1;}rc = make_tree(root->left,str);if(!rc)return rc;rc = make_tree(root->right,str);if(!rc)return rc;printf("tree root is %c\n",root->val);printf("dump buf[cou_t-3] %c buf[cou_t-2] %c buf[cou_t-1] %c\n",buf[cou_t-3],buf[cou_t-2],buf[cou_t-1]);if((buf[cou_t-1]=='@')||(buf[cou_t-2]=='@')||(buf[cou_t-3]=='@')){cou_t -= 2;return 1;}if((buf[cou_t-3]<buf[cou_t-2])||(buf[cou_t-3]>buf[cou_t-1])){printf("err!\n");return 0;}cou_t -= 2;return 1;}int get_input(char *str){gets(str);puts(str);//printf("\nlens is %d\n", strlen(str));length = strlen(str);return strlen(str);}void main(void){char str[30];int rc;printf("hello cygwin\n");struct TreeNode *root;get_input(str);rc = make_tree(root , str);if(rc)printf("good\n");elseprintf("bad\n");}

3th Validate Binary Search Tree相关推荐

  1. [CareerCup] 4.5 Validate Binary Search Tree 验证二叉搜索树

    4.5 Implement a function to check if a binary tree is a binary search tree. LeetCode上的原题,请参见我之前的博客Va ...

  2. LeetCode:Validate Binary Search Tree

    题目链接 Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defin ...

  3. LeetCode 之 JavaScript 解答第98题 —— 验证二叉搜索树(Validate Binary Search Tree)

    Time:2019/4/24 Title: Vaildata Binary Search Tree Difficulty: Medium Author: 小鹿 题目:Vaildata Binary S ...

  4. LeetCode Validate Binary Search Tree(dfs)

    问题:判断树是否是合法的二叉搜索树 思路: 1.在dfs时,判断当前结点是否大于左子树的最大值,小于右子树的最小值.这是一种思路 2.另外一个思路是在中序遍历时,用个变量记录当前结点的前驱结点,再判断 ...

  5. 098 Validate Binary Search Tree 验证二叉搜索树

    给定一个二叉树,判断其是否是一个有效的二叉搜索树. 一个二叉搜索树有如下定义:     左子树只包含小于当前节点的数.     右子树只包含大于当前节点的数.     所有子树自身必须也是二叉搜索树. ...

  6. LeetCode --- Validate Binary Search Tree

    题目链接 判断一颗二叉树是否是二叉搜索树(二叉排序树),也就是BST 如果该二叉树是BST, 那么对其中序遍历,所得序列一定是单调递增的(不考虑有重复数值的情况) 附上代码: 1 /** 2 * De ...

  7. 98. Validate Binary Search Tree

    不定期更新leetcode解题java答案. 采用pick one的方式选择题目. 题目要求判断树是否为二叉搜索树.要求为:1.一个节点的左子树的所有节点均小于该节点:2.一个节点的右子树上的所有节点 ...

  8. 判断一颗二叉树是否为二叉搜索树(Validate Binary Search Tree)

    一.学习要点: 利用二叉搜索树的中序遍历为递增数组的性质: 二.代码: void middle(node* root,vector<int>& inorder) {if(root= ...

  9. Leetcode: Validate Binary Search Tree

    思路: 1. 难点在于构造递归函数的参数 2. 参数要包含上下界, 才能具有全局性. 第一次提交 WA 了, 因为写成来的判断函数是局部性的 代码: const int POS = 1E9; cons ...

最新文章

  1. cgroups是什么
  2. 用正则表达式取出table中的所有行(支持嵌套table)
  3. MyBatis 源码分析系列文章合集
  4. 吴恩达作业6:梯度检验
  5. SpringBoot微服务项目构建war包 部署排除指定jar
  6. 10.9 自动注册DSN和创建表
  7. android 电话拦截短信验证码,全警出击,只为寻找一位正在买新手机的女士……...
  8. 使用IDEA编写一个springMVC架构的HelloWorld
  9. Python基础语法
  10. Java——数据结构与算法
  11. Linux中jemalloc的安装与使用
  12. 《大学“电路分析基础”课程实验合集.实验一》丨元器件的检测及万用表的使用
  13. 公路通用复化辛普森公式匝道点位坐标计算4800源程序
  14. lisp 定距等分_CAD点命令快捷键(定数等分及定距等分)
  15. 北京城市学院计算机本科就业率高吗,北京城市学院就业情况怎么样
  16. vuecli项目打包
  17. Django工程中,pycharm运行manage.py,提示8000端口占用问题error:That port is already in use
  18. Linux 性能监控分析
  19. 出现身份验证错误,要求的函数不支持,
  20. 数据结构之二叉树的前中后序遍历以及层序遍历

热门文章

  1. 关于陶瓷电容温度系数代码,这是我见过最全面的解读
  2. [VisionPro] CogFixtureTool 工具详解
  3. 微信小程序获取当前经纬度
  4. 亚商投资顾问 早餐FM/1123 加快构建与国际相衔接的金融制度体系和监管模式
  5. iconfont 转换为图标字体
  6. ACPI相关(8)- ACPI Platform Error Interfaces
  7. 基于深度学习的道路交通标志数字识别
  8. vnc 软件 linux,vnc-E4_6_2-x86_x64_win32远程桌面linux工具下载
  9. php 内置的 web 服务器
  10. 数据库数据加密及其他安全性保护