当前位置:网站首页>完全二叉搜索树 (30 分)
完全二叉搜索树 (30 分)
2022-04-23 08:35:00 【怀化第二深情】
一个无重复的非负整数序列,必定对应唯一的一棵形状为完全二叉树的二叉搜索树。本题就要求你输出这棵树的层序遍历序列。
输入格式:
首先第一行给出一个正整数 N(≤1000),随后第二行给出 N 个不重复的非负整数。数字间以空格分隔,所有数字不超过 2000。
输出格式:
在一行中输出这棵树的层序遍历序列。数字间以 1 个空格分隔,行首尾不得有多余空格。
输入样例:
10
1 2 3 4 5 6 7 8 9 0
输出样例:
6 3 8 1 5 7 9 0 2 4
#include<bits/stdc++.h>
using namespace std;
int g[1010],in[1010];
int id,n;
void pre(int root){
if(root>n)return;
pre(root*2);
in[root]=g[id++];
pre(root*2+1);
}
int main(){
cin>>n;
for(int i=0;i<n;i++)cin>>g[i];
sort(g,g+n);
pre(1);
cout<<in[1];
for(int i=2;i<=n;i++)cout<<" "<<in[i];
}
版权声明
本文为[怀化第二深情]所创,转载请带上原文链接,感谢
https://blog.csdn.net/dege2929512534/article/details/124339415
边栏推荐
- 测试你的机器学习流水线
- idea配置连接远程数据库MySQL,或者是Navicat连接远程数据库失败问题(已解决)
- Swagger document export custom V2 / API docs interception
- [C语言] 文件操作《一》
- 根据字节码获取类的绝对路径
- On time atom joins hands with oneos live broadcast, and the oneos system tutorial is fully launched
- SYS_CONNECT_BY_PATH(column,'char') 结合 start with ... connect by prior
- 作文以记之 ~ 二叉树的后序遍历
- Failed to prepare device for development
- How much inventory recording does the intelligent system of external call system of okcc call center need?
猜你喜欢

跨域配置报错: When allowCredentials is true, allowedOrigins cannot contain the special value “*“

idea底栏打开services

洋桃电子STM32物联网入门30步笔记三、CubeMX图形化编程、设置开发板上的IO口

Harbor企业级镜像管理系统实战

Input / output system

excle加水印

Transformer XL: attention language modelsbbeyond a fixed length context paper summary

STM32 uses Hal library. The overall structure and function principle are introduced

作文以记之 ~ 二叉树的前序遍历

四张图弄懂matplotlib的一些基本用法
随机推荐
QT compilation qtxlsx Library
测试你的机器学习流水线
idea配置连接远程数据库MySQL,或者是Navicat连接远程数据库失败问题(已解决)
Virtual online exhibition - Online VR exhibition hall realizes 24h immersive exhibition viewing
洋桃电子STM32物联网入门30步笔记三、CubeMX图形化编程、设置开发板上的IO口
数据可视化:使用Excel制作雷达图
rembg 分割mask
STM32 uses Hal library. The overall structure and function principle are introduced
Noyer électronique stm32 Introduction à l'Internet des objets 30 étapes notes I. différences entre la Bibliothèque Hal et la Bibliothèque standard
Add random attributes to the Li class array objects and sort them
请问中衍期货安全靠谱吗?
作文以记之 ~ 二叉树的前序遍历
Overview of bus structure
虚拟线上展会-线上vr展馆实现24h沉浸式看展
ajax防止缓存方法
Flash project cross domain interception and DBM database learning [Baotou cultural and creative website development]
swagger文档导出自定义v2/api-docs拦截
form中enctype属性
00后最关注的职业:公务员排第二,第一是?
匿名类型(C# 指南 基础知识)