【PAT (Advanced Level) Practice】1086 Tree Traversals Again (25 分)

短命女 2023-01-24 02:08 137阅读 0赞

众所周知只有前序遍历和后序遍历是不可能推出中序遍历的,所以我就不废话了

由树的前序遍历和中序遍历可以推后序遍历
由树的中序遍历和后序遍历可以推前序遍历

  1. #include <cstdio>
  2. #include <vector>
  3. #include <stack>
  4. #include <cstring>
  5. using namespace std;
  6. vector<int> pre, in, post,value; void postorder(int root, int start, int end) {
  7. if (start > end) return;
  8. int i = start;
  9. while (i < end && in[i] != pre[root]) i++;

发表评论

表情:
评论列表 (有 0 条评论,137人围观)

还没有评论,来说两句吧...

相关阅读