当前位置:网站首页>L2-035 sequence traversal of complete binary tree (25 points)
L2-035 sequence traversal of complete binary tree (25 points)
2022-04-23 00:36:00 【hys__ handsome】
Topic details - L2-035 Sequence traversal of complete binary tree (25 branch ) (pintia.cn)
Ideas : Perfect binary tree ( If the root node is i, Left son for i*2, The right son is i*2+1), Its sequence traversal is :1,2,3,……,n. With this conclusion, we can directly simulate the input of post order traversal , Then output the array in sequence .
#include<iostream>
using namespace std;
const int N = 40;
int a[N];
int n;
void dfs(int u){
int l = u*2, r= u*2+1;
if(l <= n) dfs(l);
if(r <= n) dfs(r);
cin>>a[u];
}
int main(){
cin>>n;
dfs(1);
for(int i = 1; i <= n; i++){
if(i != 1) cout<<' ';
cout<<a[i];
}
return 0;
}
版权声明
本文为[hys__ handsome]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230033479227.html
边栏推荐
- Binary search tree from preorder to preorder and postorder
- A tikv hard disk usage problem caused by GC not working caused by ticdc exception
- 随笔8:错误解决Error in readPNG(paste(location,“/“,pattern.type[i],“.png“,sep = ““)):unable to open C:/
- [image classification] - come on, let's do this bowl of efficientnet combat (pytoch)
- L2-011 playing with binary tree (25 points)
- MP2459被完美替代内部集成有功率MOSFET管FS2459的60V0.5A降压IC
- Object size and pointer compression -- JVM
- L2-035 完全二叉树的层序遍历 (25 分)
- Install authorizationpolicy and envoyfilter
- 层次分析法软件操作步骤(yaahp)
猜你喜欢

Beginner MCU lights up the first peripheral -- led light
(turn) how is word2016 compatible with MathType

【图像分类】用最简短的代码复现SeNet,小白一定要收藏(keras,Tensorflow2.x)

群体智能协同作业与认知计算技术研究

Symbolization of ArcGIS surface tin surface data

深度学习基础学习-RNN与LTSM

while (n-- > 0) 的用法

植被物候参数遥感研究进展(好文分享)
![[image classification] reproduce senet with the simplest code. Beginners must not miss (pytorch)](/img/6d/9e066060b0b5b792d5a5a3c1b4c594.png)
[image classification] reproduce senet with the simplest code. Beginners must not miss (pytorch)

ArcMap uses drawing tools to add annotations
随机推荐
ACWing春季每日一题——你知道ABC吗
接口文档生成工具ApiPost 绝了
Static and dynamic control nixie tube
对Indexlookup的理解误区
洛谷P2241统计方形
L2-021 点赞狂魔 (25 分)
Beginner MCU lights up the first peripheral -- led light
Misunderstanding of indexlookup
ArcGIS 计算地块容积率
April 22, 2022, day 15
申请CA证书的步骤
网线IP配置
ArcGIS 城市生活区用地适宜性评价(五)
二叉搜索树前序序列转中序和后序
Deletes all specified elements in the vector
程序员怎么找工作?程序员找工作越来越难怎么办?
According to this effective method, UI automation testing is so simple
Acwing spring daily question - do you know ABC
L2-012 关于堆的判断 (25 分)(字符串bug待解决)
Steps to apply for a CA certificate