当前位置:网站首页>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
边栏推荐
- Recommend reading | share the trader's book list and ask famous experts for trading advice. The trading is wonderful
- The most easy to understand dependency injection and control inversion
- 交换二叉树中每个结点的左和右
- 編碼電機PID調試(速度環|比特置環|跟隨)
- c#可变参数params的介绍
- 宁德时代地位不保?
- 再战leetcode (290.单词规律)
- tf. keras. layers. Conv? D function
- 腾讯视频涨价:一年多赚74亿!关注我领取腾讯VIP会员,周卡低至7元
- LNMP MySQL allows remote access
猜你喜欢
C# WPF UI框架MahApps切换主题
C#中切片语法糖的使用
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).
2022年度Top9的任务管理系统
Tips in MATLAB
腾讯视频涨价:一年多赚74亿!关注我领取腾讯VIP会员,周卡低至7元
tf. keras. layers. Conv? D function
AC & A2C & A3C
荐读 | 分享交易员的书单,向名家请教交易之道,交易精彩无比
C# 11 的这个新特性,我愿称之最强!
随机推荐
Deep q-network (dqn)
Openfeign details show
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
Xamarin效果第二十二篇之录音效果
C#中切片语法糖的使用
Xamarin效果第二十一篇之GIS中可扩展浮动操作按钮
ASP.NET和ASP.NETCore多环境配置对比
Basic SQL (VIII) data update operation practice
How to write the expected salary on your resume to double your salary during the interview?
Judge whether there is a leap year in the given year
Systemctl start Prometheus + grafana environment
The whole network is the most complete. How to do interface automation test? Proficient in interface automation test details
微软是如何解决 PC 端程序多开问题的——内部实现
Thoughts on the 2022 national network security competition of the national secondary vocational group (only one idea for myself) - network security competition questions (8)
A set of C interview questions about memory alignment. Many people make mistakes!
Creating wechat voucher process with PHP
全网最全,接口自动化测试怎么做的?精通接口自动化测试详解
求二叉树的叶子结点个数
7-11 rearrange the linked list (25 points)
Introduction and use of openfeign component