当前位置:网站首页>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
边栏推荐
- Laravel new route file
- What kind of experience is it to prepare for a month to participate in ACM?
- In redis cluster, the master node fails, and the IP changes after the master-slave switch. The client does not need to deal with it
- Source Generator实战
- tf. keras. layers. Embedding function
- Maui initial experience: Cool
- Notes sur le développement de la tarte aux framboises (XII): commencer à étudier la suite UNO - 220 de la tarte aux framboises de contrôle industriel advantech (i): Introduction et fonctionnement du s
- MYSQL05_ Ordr by sorting, limit grouping, group by grouping
- C#中切片语法糖的使用
- svg标签中利用<polygon/>循环数组绘制多边形
猜你喜欢

Xamarin效果第二十二篇之录音效果

LNMP MySQL allows remote access

C read / write binary file

Dynamic sequence table + OJ

樹莓派開發筆記(十二):入手研華ADVANTECH工控樹莓派UNO-220套件(一):介紹和運行系統

TP5 email (2020-05-27)

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).

最通俗易懂的依赖注入之服务容器与作用域

TP5 customization in extend directory succeeded and failed. Return information

由于3²+4²=5²,所以称‘3,4,5‘为勾股数,求n(包括n)以内所有勾股数数组。
随机推荐
TP5 email (2020-05-27)
基于.NetCore开发博客项目 StarBlog - (1) 为什么需要自己写一个博客?
Tencent video price rise: earn more than 7.4 billion a year! Pay attention to me to receive Tencent VIP members, and the weekly card is as low as 7 yuan
交换二叉树中每个结点的左和右
TP5 multi conditional where query (using PHP variables)
Assembly learning Chapter III of assembly language (Third Edition) written by Wang Shuang
.Net Core 限流控制-AspNetCoreRateLimit
The whole network is the most complete. How to do interface automation test? Proficient in interface automation test details
Blazor University (11) component - replace attributes of subcomponents
HLS / chisel practice CORDIC high performance computing complex square root
Thoughts on the 2022 national network security competition of the national secondary vocational group (only one idea for myself) - network security competition questions (8)
使用栈来解决”迷你语法分析器“的问题
最通俗易懂的依赖注入之服务容器与作用域
Openfeign service call
[ncnn] - the meaning of - 23300 in param
2022T电梯修理考试模拟100题及在线模拟考试
Detailed explanation of distributed things
Openfeign timeout setting
C read / write binary file
Mise en service PID du moteur de codage (anneau de vitesse | anneau de position | suivant)