当前位置:网站首页>DS inner row heap sort
DS inner row heap sort
2022-07-24 14:49:00 【Running star dailu】
Title Description
Given a set of data , Use heap sort to sort the data in descending order .( Build a small top pile ).
Input
The number of data n,n Integer data
Output
Initially created small top heap sequence
Exchange per trip 、 Filtered data sequence , See the example for the output format
The sample input
8 34 23 677 2 1 453 3 7
Sample output
8 1 2 3 7 23 453 677 34
8 2 7 3 34 23 453 677 1
8 3 7 453 34 23 677 2 1
8 7 23 453 34 677 3 2 1
8 23 34 453 677 7 3 2 1
8 34 677 453 23 7 3 2 1
8 453 677 34 23 7 3 2 1
8 677 453 34 23 7 3 2 1Code
#include "bits/stdc++.h"
using namespace std;
const int maxn=1e5+20;
int n,a[maxn];
void display(){
cout<<n;
for(int i=0;i<n;i++){
cout<<" "<<a[i];
}
cout<<endl;
}
void chang(int id,int n){
int l=id*2+1,r=id*2+2;
if(l<n){
if(r<n){
if(a[l]<a[r]){
if(a[l]<a[id]){
swap(a[l],a[id]);
chang(l,n);
}
}
else if(a[r]<a[id]){
swap(a[r],a[id]);
chang(r,n);
}
}
else{
if(a[l]<a[id]){
swap(a[l],a[id]);
chang(l,n);
}
}
}
}
int main(){
// freopen("123.in","r",stdin);
cin>>n;
for(int i=0;i<n;i++){
cin>>a[i];
}
for(int i=n/2;i>=0;i--){
chang(i,n);
}
display();
for(int i=n-1;i>0;i--){
swap(a[0],a[i]);
chang(0,i);
display();
}
return 0;
}边栏推荐
- Dameng real-time active and standby cluster construction
- Leetcode · daily question · 1184. distance between bus stops · simulation
- A common Dao class and util
- [oauth2] IV. oauth2authorizationrequestredirectfilter
- Beijing all in one card listed and sold 68.45% of its equity at 352.888529 million yuan, with a premium rate of 84%
- Unity 委托 (Delegate) 的简单理解以及实现
- C unsafe unmanaged object pointer conversion
- 对话框管理器第二章:创建框架窗口
- AtCoder Beginner Contest 261E // 按位思考 + dp
- CSDN垃圾的没有底线!
猜你喜欢

Problem handling of repeated restart during Siemens botu installation

VSCode如何调试Nodejs

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

北京一卡通以35288.8529万元挂牌出让68.45%股权,溢价率为84%

Operation of MySQL Library

Kotlin类与继承

茅台冰淇淋“逆势”走红,跨界之意却并不在“卖雪糕”

Class loading mechanism and parental delegation mechanism

深度学习中的学习率调整策略(1)
![Rasa 3.x 学习系列-Rasa [3.2.4] - 2022-07-21 新版本发布](/img/1e/27f107d514ded6641410cc5a45764b.png)
Rasa 3.x 学习系列-Rasa [3.2.4] - 2022-07-21 新版本发布
随机推荐
Conflict resolution of onblur and onchange
Rasa 3.x learning series -rasa [3.2.4] - 2022-07-21 new release
Overview of dobesie wavelet (DB wavelet function) in wavelet transform
C unsafe unmanaged object pointer conversion
Unity uses NVIDIA flex for unity plug-in to realize the effects of making software, water, fluid, cloth, etc. learning tutorial
【MATLAB】MATLAB画图系列二 1.元胞与数组转化 2.属性元胞 3.删除nan值 4.合并多fig为同一fig 5.合并多fig至同一axes
Comparison of traversal speed between map and list
电赛设计报告模板及历年资源
PrestoUserError: PrestoUserError(type=USER_ERROR, name=INVALID_FUNCTION_ARGUMENT, message=“Escape st
Google Earth Engine——使用MODIS数据进行逐月数据的过火(火灾)面积并导出
佣金哪家券商最低,我要开户,手机上开户安不安全
Binlog and iptables prevent nmap scanning, xtrabackup full + incremental backup, and the relationship between redlog and binlog
Caffe framework and production data source for deep learning
股票开户之后就可以购买6%的理财产品了?
SQL Server syntax - create database
Don't lose heart. The famous research on the explosive influence of Yolo and PageRank has been rejected by the CS summit
Extjs4 instance address and Chinese document address
Overall testing framework for performance testing
spark:指定日期输出相应日期的日志(入门级-简单实现)
binlog、iptables防止nmap扫描、xtrabackup全量+增量备份以及redlog和binlog两者的关系