【发布时间】:2021-12-16 03:43:06
【问题描述】:
需要验证给定的前序遍历是否是 BST?输入是包含二叉树的前序遍历的文件,以及节点是否有左、右、两个子节点或没有子节点。例如
-2 3
-4 3
-5 0
-3 0
2 3
0 3
-1 0
1 0
5 1
4 0
表示“-2”节点同时具有左右子节点。 “-5”没有孩子。基本上
0 -> no children
1 -> right child
2 -> left child
3 -> both Children
这是不能修改的节点结构
typedef struct _Tnode {
int key;
int height;
struct _Tnode *left;
struct _Tnode *right;
} Tno
PS:在此示例中,它不是 BST。我可以用它构建的树看起来像这样
-2
/ \
/ \
-4 2
/ \ / \
-5 -3 0 5
/ \ \
-1 1 4
【问题讨论】:
-
请花一些时间刷新the help pages,采取SO tour,阅读How to Ask,以及this question checklist。最后,请edit你的问题来改进它,例如实际提出一个问题......你有什么问题?您有自己尝试的minimal reproducible example 吗?你有什么问题?
-
我花了相当多的时间研究这个问题,但没有找到任何解决方案。也更新问题
标签: c data-structures binary-search-tree avl-tree