当前位置:网站首页>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;
}边栏推荐
- PrestoUserError: PrestoUserError(type=USER_ERROR, name=INVALID_FUNCTION_ARGUMENT, message=“Escape st
- Rest style
- pip换源
- Summary of Baimian machine learning
- Overall testing framework for performance testing
- C operator priority memory formula
- Problems needing attention in mobile terminal testing
- Rasa 3.x learning series -rasa [3.2.3] - new version released on July 18, 2022
- dataframe 分组后排序的前n行 nlargest argmax idmax tail !!!!
- 2022年IAA行业品类发展洞察系列报告·第二期
猜你喜欢

Data analysis and mining 1

小熊派 课程导读

使用 Fiddler Hook 报错:502 Fiddler - Connection Failed

Mini examination - examination system

关于构建网络安全知识库方向相关知识的学习和思考

LeetCode高频题56. 合并区间,将重叠的区间合并为一个区间,包含所有区间

深入浅出边缘云 | 2. 架构

Under multi data source configuration, solve org.apache.ibatis.binding Bindingexception: invalid bound statement (not found) problem

Strongly connected component

Grpc middleware implements grpc call retry
随机推荐
Rest style
The accuracy of yolov7 in cracking down on counterfeits, not all papers are authentic
Detailed explanation of IO model (easy to understand)
CSDN garbage has no bottom line!
Bibliometrix: dig out the one worth reading from thousands of papers!
Must use destructuring props assignmenteslint
C unsafe unmanaged object pointer conversion
Is it safe for Huatai Securities to open an account? Can it be handled on the mobile phone?
Dialog manager Chapter 2: create frame window
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
正则表达和绕过案例
Rasa 3.x 学习系列-Rasa FallbackClassifier源码学习笔记
Caffe framework and production data source for deep learning
Preparation of mobile end test cases
电赛设计报告模板及历年资源
多数据源配置下,解决org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)问题
The server switches between different CONDA environments and views various user processes
Can you buy 6% of financial products after opening a stock account?
Atcoder beginer contest 261e / / bitwise thinking + DP
Spark: specify the date and output the log of the corresponding date (entry level - simple implementation)