#include <iostream>
#include<bits/stdc++.h>
using namespace std;
void HeapAdjust(int *a,int s,int length){
int t=a[s];
for(int i=2*s;i<=length;i=i*2){
if(i+1<=length&&a[i]<a[i+1]) i=i+1;
if(t>a[i]) break;
a[s]=a[i];s=i;
}
a[s]=t;
}
void CreatHead(int *a,int x){
for(int i=x/2;i>0;i--)
HeapAdjust(a,i,x);
}
void HeapSort(int *a,int length){
CreatHead(a,length);
for(int i=length;i>1;i--){
int x=a[1];
a[1]=a[i];
a[i]=x;
HeapAdjust(a,1,i-1);
}
}
int main()
{
int a[100];
int x,i=1;
cin>>x;
while(x){
a[i++]=x;
cin>>x;
}
HeapSort(a,i-1);
for(int j=1;j<=i-1;j++)
cout<<a[j]<<" ";
//cout << "Hello world!" << endl;
return 0;
}
8550 algorithme de tri de tas
Je suppose que tu aimes
Origine blog.csdn.net/changbaishannefu/article/details/111648085
conseillé
Classement