ICode9

精准搜索请尝试: 精确搜索
  • pta L2-006 树的遍历(根据后序中序确定层序)2022-04-21 17:01:15

    题目链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805069361299456 对树的遍历考的很周到,第一次接触到确定层序序列的题; 题目思路:建树函数和根据前中序序列确定后序序列思想是相同的,但是在细节方面还是存在差异,比如:    我们可以根据题目的要求画个图 拿

  • 1020 Tree Traversals (25 分)2022-02-25 17:05:31

    Suppose that all the keys in a binary tree are distinct positive integers. Given the postorder and inorder traversal sequences, you are supposed to output the level order traversal sequence of the corresponding binary tree. Input Specification: Each input

  • 已知树的先序遍历和中序遍历求后序遍历2022-02-17 23:32:27

    利用递归将每一个结点看成根结点 #include <iostream> using namespace std; int pre[10], in[10];//先序和中序 int post[10];//后序 void solve(int prel, int inl, int postl, int n) {//分别是数组下标 int i; if (n == 0) return ; if (n == 1) { post[postl] = pr

  • 1020 Tree Traversals (25 分)/中序遍历+后序遍历转为层次遍历2022-02-09 11:31:12

    #include<iostream> #include<queue> #include<algorithm> #include<stdio.h> using namespace std; struct node { int data; node* lchild; node* rchild; }; const int maxn=50; int n,pre[maxn],post[maxn],in[maxn]; node* create

  • 1127 ZigZagging on a Tree (30 分)2021-07-10 14:05:28

    蛇形输出层序遍历,这个只要记录每一层的遍历序列,然后输出之前该翻转的翻转一下就可以了,然后看了看自己一年之前提交的,思路真的是一模一样,就是代码风格变了, #include <bits/stdc++.h> #define fi first #define se second #define pb push_back #define all(x) (x).begin(), (

  • 1127 ZigZagging on a Tree(30分)2021-02-24 21:01:58

    假设二叉树中的所有键都是不同的正整数。可以通过给定的一对后序遍历和有序遍历序列来确定唯一的二叉树。这是一个简单的标准例程,可以按级别顺序打印数字。但是,如果您认为问题太简单了,那就太天真了。这次,您应该按“曲折顺序”打印数字-也就是说,从根开始,逐级打印数字,从左到右和从右

  • PATA 1020 Tree Traversals2021-02-21 17:59:52

    题目大意: 给定二叉树的后根序列和中根序列,输出层次序列。 输入: 第一行:节点个数 第二行:后根序列 第三行:中根序列 输出: 层次序列,数字间用一个空格隔开,末尾不允许有多余空格。 代码: #include <stdio.h> #include <queue> using namespace std; const int maxn=40; int post[m

  • 【leetcode 二叉树 C++】【剑指 Offer】 33. 二叉搜索树的后序遍历序列2021-01-28 21:01:21

    剑指 Offer 33. 二叉搜索树的后序遍历序列 class Solution { public: bool buildTree(vector<int> &postorder, vector<int> &inorder, int postL, int postR, int inL, int inR) { if(postR == postL && inR == inL) return true; if(pos

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有