首页
DreamJudge
院校信息
专业题库
模拟考试
机试真题
408真题
专业课程
兑换中心
登录
注册
上岸
以下题解仅供学习参考使用。
抄袭、复制题解,以达到刷AC率/AC数量或其他目的的行为,在N诺是严格禁止的。
N诺非常重视学术诚信。此类行为将会导致您成为作弊者。具体细则请查看N诺社区规则。
老猫
2021年1月19日 15:56
递归大法
P1401
回复 3
|
赞 54
|
浏览 9.0k
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...
carrot_huan
2025年3月10日 17:35
二叉树遍历2 题解:递归建树
P1401
回复 0
|
赞 12
|
浏览 379
#include<iostream> #include<string> using namespace std; struct TreeNode { char data; TreeNode* rchild, * lchild; }; void BuildTree(string pre, string mid, TreeNode*& root) { if (pre.size() == 0) { root =...
chenxx
2025年3月4日 22:08
二叉树遍历2 题解:
P1401
回复 0
|
赞 1
|
浏览 299
#include <bits/stdc++.h> using namespace std; struct tree { char val; tree* left; tree* right; tree(char n) : val(n), left(nullptr), right(nullptr) {} }; // 根据前序和中序遍历构建二叉树 tree* create(const string& pre, const string&a...
西电机试专家
2025年3月2日 10:42
二叉树遍历2 题解:带了一些注释
P1401
回复 0
|
赞 16
|
浏览 375
#include<bits/stdc++.h> using namespace std; typedef struct node { char data; struct node* left, * right; }* bt; string qian,zhong;//前序和中序遍历序列 int cnt=0;//用于记录当前根节点在先序遍历位置 void createTree(int low, int high, bt &T) {//注意&,...
RingoCrystal
2025年2月4日 14:04
二叉树遍历2 题解:利用先序建树
P1401
回复 0
|
赞 4
|
浏览 385
#include <bits/stdc++.h> using namespace std; struct tnode{ char val; tnode *left,*right; tnode():val(' '),left(nullptr),right(nullptr){} tnode(char c):val(c),left(nullptr),right(nullptr){} }; tnode* buildTree(string preOrder,string inOrder){ if(preOrder.e...
1935569240
2024年3月9日 16:02
二叉树遍历2 题解:简单递归建树方法如下:
P1401
回复 0
|
赞 6
|
浏览 1.1k
#include<iostream> #include<algorithm> #include<string> using namespace std; struct node { char ch; struct node* left, * right; }; string forStr,cenStr; int len, cnt=0; struct node* createTree(int low, int high, struct node...
孙某人
2024年2月27日 11:57
二叉树遍历2 题解:新手总结
P1401
回复 0
|
赞 6
|
浏览 1.0k
#include <iostream> #include<string.h> using namespace std; //typedef struct node { //int data; //struct node *lchild,*rchild; //}node,*Tnode; void postnode(char *pre,char *mid,int *p,int start,int end){ char cc; int c; if(pre[*p]!='\n'&&start<=end) {...
我才不怕编程
2023年3月13日 17:09
差别在建树方法
P1401
回复 0
|
赞 7
|
浏览 3.1k
#include <bits/stdc++.h> using namespace std; typedef struct node { char data; struct node *lchild,*rchild; } node,*Tree; void createTree (Tree &T,string pre,string in) { T=new node;T->lchild=NULL;T->rchild=NULL; T->data=pre[0]; if(pre.size()==1) return; ...
shmilyzsc
2021年2月22日 11:56
递归解法(未使用链表构建)
P1401
回复 0
|
赞 4
|
浏览 10.7k
#include <bits/stdc++.h> using namespace std; vector<char> pre, in, post; int cnt; string a,b; void recons(int l, int r) { if(l >= r) return; char root = pre[cnt++]; int m = distance(in.begin(), find(in.begin(), in.end(), root)); recons(l, m); r...
James
2021年2月1日 14:09
根据先序和中序建二叉树 注意递归边界
P1401
回复 0
|
赞 6
|
浏览 8.8k
#include<iostream> #include<queue> #include<string> #include<string.h> using namespace std; typedef struct node{ char data; struct node*lchild; struct node*rchild; }BiNode,*BiTree; int m,n; char pre[27];...
1
2
题目
二叉树遍历2
题解数量
11
发布题解
在线答疑
热门题解
1
递归大法
2
二叉树遍历2 题解:带了一些注释
3
二叉树遍历2 题解:递归建树
4
二叉树遍历(C)
5
差别在建树方法
6
二叉树遍历2 题解:新手总结
7
二叉树遍历2 题解:简单递归建树方法如下:
8
根据先序和中序建二叉树 注意递归边界
9
二叉树遍历2 题解:利用先序建树
10
递归解法(未使用链表构建)