当前位置:网站首页>Establishing and traversing binary tree
Establishing and traversing binary tree
2022-04-23 03:07:00 【Learning KL & TK】
Define the pre order sequence of a binary tree in the form of string , If the character is ‘#’, Indicates that the binary tree is empty , Otherwise, the character is the data element of the corresponding node . Read in the corresponding sequence , establish Binary storage structure Two fork tree , Then traverse the binary tree in middle order and output node data .
sample input :
Here's a set of inputs . for example :
ABC##DE#G##F###
sample output :
Here is the corresponding output . for example :
CBEGDFA
#include "bits/stdc++.h"
using namespace std;
struct Tree{
char val;
Tree* lchild;
Tree* rchild;
};
Tree* build(){
char c;
cin >> c;
if(c=='#') return NULL;
Tree* root = new Tree();
root->val = c;
root->lchild = build();
root->rchild = build();
return root;
}
void dfs(Tree* root){
if(root == NULL) return;
dfs(root->lchild);
cout << root->val ;
dfs(root->rchild);
}
int main()
{
Tree* root = build();
dfs(root);
return 0;
}
版权声明
本文为[Learning KL & TK]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230303365591.html
边栏推荐
- 编码电机PID调试(速度环|位置环|跟随)
- 宁德时代地位不保?
- Source code interpretation of Flink index parameters (read quantity, sent quantity, sent bytes, received bytes, etc.)
- 微软是如何解决 PC 端程序多开问题的——内部实现
- 一套关于 内存对齐 的C#面试题,做错的人很多!
- Thoughts on the 2022 national network security competition of the national secondary vocational group (only one idea for myself) - network security competition questions (9)
- Recommend reading | share the trader's book list and ask famous experts for trading advice. The trading is wonderful
- Use DFS to solve the problem of "number of dictionary rows"
- 樹莓派開發筆記(十二):入手研華ADVANTECH工控樹莓派UNO-220套件(一):介紹和運行系統
- Some problems encountered in setting Django pure interface, channel and MySQL on the pagoda panel
猜你喜欢

Response processing of openfeign

Introduction and use of openfeign component

Impact of AOT and single file release on program performance

Blazor University (11)组件 — 替换子组件的属性

搭建XAMPP时mysql端口被占用

微软是如何解决 PC 端程序多开问题的——内部实现

腾讯视频VIP会员,周卡特价9元!腾讯官方直充,会员立即生效!

Blazor University (11) component - replace attributes of subcomponents

ASP. Net and ASP NETCORE multi environment configuration comparison

Due to 3 ²+ four ²= five ², Therefore, we call '3,4,5' as the number of Pythagorean shares, and find the array of all Pythagorean shares within n (including n).
随机推荐
编码电机PID调试(速度环|位置环|跟随)
中后二叉建树
使用DFS来解决“字典序排数”问题
Using stack to solve the problem of "mini parser"
TP5 where query one field is not equal to multiple values
What kind of experience is it to prepare for a month to participate in ACM?
Xamarin效果第二十二篇之录音效果
由于3²+4²=5²,所以称‘3,4,5‘为勾股数,求n(包括n)以内所有勾股数数组。
Introduction and use of openfeign component
Summary of software test interview questions
How does Microsoft solve the problem of multiple programs on PC side -- internal implementation
Mise en service PID du moteur de codage (anneau de vitesse | anneau de position | suivant)
Summary of interface automation interview questions for software testing
C#中切片语法糖的使用
Vs code setting line feed
腾讯视频VIP会员,周卡特价9元!腾讯官方直充,会员立即生效!
How to count the number of all files in a directory under win10 system
Passing object type parameters through openfeign
Openfeign details show
TP5 inherits base and uses the variables in base