当前位置:网站首页>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
边栏推荐
- Development notes of raspberry pie (12): start Advantech industrial control raspberry pie uno-220 Kit (I): introduction and operation of the system
- TP5 email (2020-05-27)
- Introduction and use of openfeign component
- 荐读 | 分享交易员的书单,向名家请教交易之道,交易精彩无比
- 【新版发布】ComponentOne 新增 .NET 6 和 Blazor 平台控件支持
- Openfeign timeout setting
- Depth deterministic strategy gradient (ddpg)
- Binary tree
- ASP. Net and ASP NETCORE multi environment configuration comparison
- 腾讯视频涨价:一年多赚74亿!关注我领取腾讯VIP会员,周卡低至7元
猜你喜欢

Judge whether there is a leap year in the given year

編碼電機PID調試(速度環|比特置環|跟隨)

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

How does Microsoft solve the problem of multiple programs on PC side -- internal implementation

The whole network is the most complete. How to do interface automation test? Proficient in interface automation test details

Tips in MATLAB

Er and eer models

ASP. Net 6 middleware series - execution sequence

Recursion - outputs continuously increasing numbers

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
随机推荐
If the deep replication of objects is realized through C #?
MYSQL04_ Exercises corresponding to arithmetic, logic, bit, operator and operator
7-11 重排链表 (25 分)
AspNetCore配置多环境log4net配置文件
C# 读写二进制文件
A set of C interview questions about memory alignment. Many people make mistakes!
ASP. Net 6 middleware series - Custom middleware classes
Creating wechat voucher process with PHP
对.NET未来的一点感悟
Tencent video VIP member, weekly card special price of 9 yuan! Tencent official direct charging, members take effect immediately!
C# WPF UI框架MahApps切换主题
最通俗易懂的依赖注入与控制反转
微软是如何解决 PC 端程序多开问题的——内部实现
Numpy append function
2022年度Top9的任务管理系统
Systemctl start Prometheus + grafana environment
求二叉树的叶子结点个数
Laravel8- use JWT
ASP. Net and ASP NETCORE multi environment configuration comparison
C# 11 的这个新特性,我愿称之最强!