当前位置:网站首页>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;
}边栏推荐
- Centos7 installs Damon stand-alone database
- Performance test - analyze requirements
- 打假Yolov7的精度,不是所有的论文都是真实可信
- Introduction to Xiaoxiong school
- Typo in static class property declarationeslint
- LeetCode·每日一题·1184.公交站间的距离·模拟
- Production environment tidb cluster capacity reduction tikv operation steps
- Rasa 3.x 学习系列-Rasa FallbackClassifier源码学习笔记
- Maotai ice cream "bucked the trend" and became popular, but its cross-border meaning was not "selling ice cream"
- How vscode debug nodejs
猜你喜欢

Strongly connected component

Introduction to Xiaoxiong school

深度学习中的学习率调整策略(1)

对话框管理器第二章:创建框架窗口
![[matlab] matlab drawing Series II 1. Cell and array conversion 2. Attribute cell 3. delete Nan value 4. Merge multiple figs into the same Fig 5. Merge multiple figs into the same axes](/img/4d/b0ba599a732d1390c5eeb1aea6e83c.png)
[matlab] matlab drawing Series II 1. Cell and array conversion 2. Attribute cell 3. delete Nan value 4. Merge multiple figs into the same Fig 5. Merge multiple figs into the same axes

Don't lose heart. The famous research on the explosive influence of Yolo and PageRank has been rejected by the CS summit
![Rasa 3.x learning series -rasa [3.2.4] - 2022-07-21 new release](/img/1e/27f107d514ded6641410cc5a45764b.png)
Rasa 3.x learning series -rasa [3.2.4] - 2022-07-21 new release

Production environment tidb cluster capacity reduction tikv operation steps

Deep learning 1 perceptron and implementation of simple back propagation network

Notes on the use of IEEE transaction journal template
随机推荐
CSDN垃圾的没有底线!
使用 Fiddler Hook 报错:502 Fiddler - Connection Failed
Property datasource is required exception handling [idea]
Learning and thinking about the relevant knowledge in the direction of building network security knowledge base
电赛设计报告模板及历年资源
How vscode debug nodejs
[NLP] next stop, embossed AI
Similarities and differences between nor flash and NAND flash
Introduction to Xiaoxiong school
Solve the problem that uni starter can log in to wechat with local functions, but fails to log in with cloud functions
PCA of [machine learning]
DDD based on ABP -- Entity creation and update
Automated penetration scanning tool
Usage differences of drop, truncate and delete
Overview of dobesie wavelet (DB wavelet function) in wavelet transform
The sliding window of Li Kou "step by step" (209. The smallest sub array, 904. Fruit baskets)
电赛设计报告模板及
The first n rows sorted after dataframe grouping nlargest argmax idmax tail!!!!
Tensorflow framework of deep learning realizes vgg/rnn network / verification code generation and recognition / text classification
深入浅出边缘云 | 2. 架构