当前位置:网站首页>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;
}边栏推荐
- VS编译后的应用缺少dll
- AtCoder Beginner Contest 261E // 按位思考 + dp
- Deep learning 1 perceptron and implementation of simple back propagation network
- Must use destructuring props assignmenteslint
- Learning and thinking about the relevant knowledge in the direction of building network security knowledge base
- Unity uses NVIDIA flex for unity plug-in to realize the effects of making software, water, fluid, cloth, etc. learning tutorial
- Usage differences of drop, truncate and delete
- The spiral matrix of the force buckle rotates together (you can understand it)
- Rasa 3.x learning series -rasa [3.2.3] - new version released on July 18, 2022
- C language -- three ways to realize student information management
猜你喜欢

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

Simple understanding and implementation of unity delegate

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

spark学习笔记(三)——sparkcore基础知识

【MATLAB】MATLAB画图系列二 1.元胞与数组转化 2.属性元胞 3.删除nan值 4.合并多fig为同一fig 5.合并多fig至同一axes

Don't lose heart. The famous research on the explosive influence of Yolo and PageRank has been rejected by the CS summit

REST风格

Spark: get the access volume of each time period in the log (entry level - simple implementation)
![Property datasource is required exception handling [idea]](/img/f3/50d36ed9445695c02e2bd622109d66.png)
Property datasource is required exception handling [idea]

Grpc middleware implements grpc call retry
随机推荐
Differences between C language pointer and array A and &a, &a[0], etc
sql server语法—创建数据库
pytorch with torch.no_ grad
Centos7 installs Damon stand-alone database
[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
Don't lose heart. The famous research on the explosive influence of Yolo and PageRank has been rejected by the CS summit
spark学习笔记(三)——sparkcore基础知识
自动化渗透扫描工具
Su Chunyuan, founder of science and technology · CEO of Guanyuan data: making business use is the key to the Bi industry to push down the wall of penetration
TypeError: Cannot read property ‘make‘ of undefined
Chiitoitsu
VSCode如何调试Nodejs
Video game design report template and resources over the years
Rasa 3.x learning series -rasa fallbackclassifier source code learning notes
[oauth2] III. interpretation of oauth2 configuration
Leetcode high frequency question 56. merge intervals, merge overlapping intervals into one interval, including all intervals
2.4. properties of special profile
The vs compiled application is missing DLL
Typo in static class property declarationeslint
记不住正则表达式?这里我整理了99个常用正则