首页
DreamJudge
院校信息
考研初试
考研复试
保研专区
讨论区
兑换中心
登录
注册
上岸
以下题解仅供学习参考使用。
抄袭、复制题解,以达到刷AC率/AC数量或其他目的的行为,在N诺是严格禁止的。
N诺非常重视学术诚信。此类行为将会导致您成为作弊者。具体细则请查看N诺社区规则。
tnz
2026年3月17日 18:15
建树后遍历 C++
P1401
回复 0
|
赞 1
|
浏览 16
#include <iostream> #include <algorithm> #include <vector> #include <string> using namespace std; struct node{ char data; node*left; node *right; }; using BitTree = node*; void addToBitTree(BitTree& t, char c, string in){ if(!t){ ...
sky952
2026年3月17日 14:02
二叉树遍历2(c语言,通过递归的思想,无需创建树)题解:
P1401
回复 0
|
赞 2
|
浏览 46
#include <stdio.h> #include <stdlib.h> #include <string.h> void postorder(char pre[],char in[],int len) { if(len<=0) return ; char root=pre[0]; int k; ...
ljh61
2026年3月16日 14:07
二叉树遍历2 题解:
P1401
回复 0
|
赞 0
|
浏览 40
学的是代码随想录的方法,代码中包括如何打印切割后的左右子树 #include <bits/stdc++.h> using namespace std; struct TreeNode{ char val; struct TreeNode *left,*right; TreeNode(char c):val(c),left(NULL),right(NULL){} }; TreeNode* build(const string& pre,c...
qtexpsem
2026年3月14日 21:10
二叉树遍历2 题解:C
P1401
回复 0
|
赞 7
|
浏览 106
#include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct node { char data; struct node *left; struct node *right; } Node; Node *build_tree (char *pre, char *in, int n) { if (n <= 0) return NULL; Node *root = (Node *)malloc(sizeof(Node)...
老猫
2021年1月19日 15:56
递归大法
P1401
回复 4
|
赞 107
|
浏览 10.5k
1、前序遍历的第一元素是整个二叉树的根节点 2、中序遍历中根节点的左边的元素是左子树,根节点右边的元素是右子树 3、后序遍历的最后一个元素是整个二叉树的根节点 #include <iostream> #include <string> #include <string.h> using namespace std; void postorder(string preorder ,string midorder) { if(preorder.size()==0) return; char root=pre...
uly
2026年3月6日 12:02
二叉树遍历2 题解:
P1401
回复 0
|
赞 14
|
浏览 157
#include <bits/stdc++.h> using namespace std; //前中序建树 string s = ""; void buildPost(string pre ,string in) { if (pre == "") return; char c = pre[0]; int pos = in.find(c); string new_inleft = in.substr(0,pos); string new_inright = in.substr(pos+1); ...
kawhileo
2026年3月4日 11:58
二叉树遍历2 题解:分治与递归的思想,
P1401
回复 0
|
赞 3
|
浏览 124
#include<bits/stdc++.h> using namespace std; //对string的熟练运用!!!!!!1401 //FDXEAG //XDEFAG void printPostorder(string preorder,string inorder){ if(preorder.empty()||inorder.empty()){ return; } char root = preord...
bro
2026年2月26日 20:30
二叉树遍历2 题解:c++
P1401
回复 0
|
赞 9
|
浏览 175
#include <bits/stdc++.h> using namespace std; typedef struct node{ char data; node *left,*right; }*Tree; void CreateTree(Tree &t,string pre,string in){ //每次确认一个根 if(pre == ""){ t =...
mlx
2026年1月28日 17:05
二叉树遍历2 题解:
P1401
回复 0
|
赞 6
|
浏览 290
#include<iostream> using namespace std; struct tr{ char c; tr *l,*r; }; void print(tr *t) { if(t==nullptr) return; print(t->l),print(t->r); cout<<t->c; } void create(tr* &t,string lift,string mid) { if(lift.size()==0) { t=nullptr; re...
cczz
2025年8月13日 18:59
已知前序遍历序列和中序遍历序列确定二叉树:(递归解决,简单易懂)
P1401
回复 0
|
赞 45
|
浏览 1.0k
例题:若一棵二叉树的前序遍历为 ABCDEF,中序遍历为 CBAEDF,请画出这棵二叉树。 分析:前序遍历第一个输出结点为根结点,故 A 为根结点。早中序遍历中根结点处于左右子树 结点中间,故结点 A 的左子树中结点有 CB,右子树中结点有 EDF。 tip:string.substr(idx, length); // idx表示开始分割的下标,length为切割的长度 #include<bits/stdc++.h> using nam...
1
2
题目
二叉树遍历2
题解数量
20
发布题解
在线答疑
热门题解
1
递归大法
2
已知前序遍历序列和中序遍历序列确定二叉树:(递归解决,简单易懂)
3
二叉树遍历2 题解:带了一些注释
4
二叉树遍历2 题解:递归建树
5
二叉树遍历2 题解:
6
二叉树遍历(C)
7
二叉树遍历2 题解:c++
8
差别在建树方法
9
二叉树遍历2 题解:简单递归建树方法如下:
10
二叉树遍历2 题解:新手总结