当前位置:网站首页>二叉树的前序遍历
二叉树的前序遍历
2022-08-04 19:37:00 【-JMY-】
题目描述
输入二叉树,输出其前序遍历。
输入
第一行表示二叉树的结点数n(n<=26)
此后n行,每一个字母为结点,后两个字母分别为其左右儿子。数据保证第一行读入的结点必为根结点。
空结点用#表示
输出
二叉树的前序遍历
样例输入
6 abc bdi cj# d## i## j##
样例输出
abdicj
参考代码:
#include<bits/stdc++.h>
using namespace std;
int n;
char c,s[30],a[30][2],x,y;
int find(char k){
for(int i=1;i<=n;i++)
if(s[i]==k)
return i;
}
void f(int i){
cout<<s[i];
if(a[i][0]!='#')
f(find(a[i][0]));
if(a[i][1]!='#')
f(find(a[i][1]));
return;
}
int main(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>c;
cin>>x;
cin>>y;
a[i][0]=x;
a[i][1]=y;
s[i]=c;
}
f(1);
return 0;
}
边栏推荐
- ELECTRA: Pre-training Text Encoders as Discriminators Rather Than Generators
- 零基础做出高端堆叠极环图
- 【Attention 演变史】RNN的产生、架构、推广、问题(第一弹)
- awk statistical difference record
- PostgreSQL的 SPI_接口函数
- If it is test axi dma catch a few words here
- MySQL远程备份策略举例
- 小软件大作用 | 如何省时省力进行Gerber图层快速对比?
- 如果是测试 axi dma抓数的话 看这里
- Video Object Detection
猜你喜欢
随机推荐
[Sql brush topic] Query information data--Day1
译文推荐|Apache Pulsar 隔离系列(四):单集群隔离策略
internship:改了需求
Chrome 开发者工具 performance 标签页的用法
awk 统计平均 最大 最小值
SAP UI5 ensures that the control id is globally unique implementation method
ERC20转账压缩
VQ Realization of Wavelet Extraction Features
really time ntp service start command
The list of Kubernetes - watch mechanism
seata源码解析:seata server各种消息处理流程
Initialization process of SAP UI5
如何手动下载并安装 Visual Studio Code 的 SAP Fiori tools - Extension Pack
Notepad++更改显示背景
如何给MySQL添加自定义语法 ?
Switch node version and switch npm source tool
《学会写作》粥佐罗著
完善的交叉编译环境记录 peta 生成的shell 脚本
Force KouTi (5), the longest text string back
A complete cross-compilation environment records the shell scripts generated by peta








