当前位置:网站首页>AG. DS binary tree -- hierarchical traversal
AG. DS binary tree -- hierarchical traversal
2022-07-24 14:47:00 【Running star dailu】
Title Description
Hierarchical ergodic binary tree , It starts from the root node , In order of hierarchy “ From top to bottom , From left to right ” Access the nodes in the tree .
The construction method is “ The first sequence traversal + Empty trees use 0 Express ” Methods
requirement : Using queue objects to implement , The function framework is as follows :

Input
Enter an integer in the first line t, Express t Test data
From the second line, enter the result of the prior traversal of the binary tree , Empty tree character ‘0’ Express , Input t That's ok
Output
Output the hierarchical traversal results of each binary tree line by line
The sample input
2
AB0C00D00
ABCD00E000FG00H0I00
Sample output
ABDC
ABFCGHDEICode
#include <bits/stdc++.h>
using namespace std;
string s;
int t;
struct NODE{
char data;
NODE *l,*r;
NODE(){
l=NULL;
r=NULL;
}
};
int id=0;
void build(NODE *&node){
if(id<s.length()){
if(s[id]=='0'){
node=NULL;
id++;
return;
}
node=new NODE;
node->data=s[id];
id++;
build(node->l);
build(node->r);
}
}
queue<NODE*> q;
void display(NODE *node){
//
q.push(node);
while(!q.empty()){
NODE *now=q.front();
q.pop();
cout<<now->data;
if(now->l) q.push(now->l);
if(now->r) q.push(now->r);
}
cout<<endl;
}
int main(){
cin>>t;
while(t--){
while(!q.empty()){
q.pop();
}
id=0;
s.clear();
cin>>s;
NODE *head=new NODE;
build(head);
display(head);
}
return 0;
}边栏推荐
- threw exception [Circular view path [index]: would dispatch back to the current handler URL [/index]
- Mysql库的操作
- spark:指定日期输出相应日期的日志(入门级-简单实现)
- Typo in static class property declarationeslint
- Which brokerage has the lowest commission? I want to open an account. Is it safe to open an account on my mobile phone
- Spark: specify the date and output the log of the corresponding date (entry level - simple implementation)
- 记不住正则表达式?这里我整理了99个常用正则
- Simple understanding and implementation of unity delegate
- DDD based on ABP -- Entity creation and update
- A common Dao class and util
猜你喜欢

REST风格

Deep learning 1 perceptron and implementation of simple back propagation network

Decrypt "sea Lotus" organization (domain control detection and defense)

Unity 委托 (Delegate) 的简单理解以及实现

看完这篇文章,才发现我的测试用例写的就是垃圾

Spark Learning Notes (III) -- basic knowledge of spark core

深度学习中的学习率调整策略(1)
![[oauth2] III. interpretation of oauth2 configuration](/img/31/90c79dbc91ee15c353ec46544c8efa.png)
[oauth2] III. interpretation of oauth2 configuration

多数据源配置下,解决org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)问题

How vscode debug nodejs
随机推荐
The difference and relation among list, set and map
Kotlin类与继承
Notes on the use of IEEE transaction journal template
北京一卡通以35288.8529万元挂牌出让68.45%股权,溢价率为84%
LeetCode高频题56. 合并区间,将重叠的区间合并为一个区间,包含所有区间
Regular expression and bypass cases
pytorch with torch.no_ grad
Unity uses NVIDIA flex for unity plug-in to realize the effects of making software, water, fluid, cloth, etc. learning tutorial
pip换源
[oauth2] II. Known changes in oauth2.1
Date processing bean
Attributeerror: module 'distutils' has no attribute' version error resolution
关于构建网络安全知识库方向相关知识的学习和思考
Data analysis and mining 2
Fraud detection cases and Titanic rescued cases
交换
Strongly connected component
threw exception [Circular view path [index]: would dispatch back to the current handler URL [/index]
[matlab] matlab drawing Series II 1. Cell and array conversion 2. Attribute cell 3. delete Nan value 4. Merge multiple figs into the same Fig 5. Merge multiple figs into the same axes
Detailed explanation of address bus, data bus and control bus