Cod sursa(job #752141)
Utilizator | Trying Here test1 | Data | 27 mai 2012 21:29:29 |
---|---|---|---|
Problema | Sortare prin comparare | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.49 kb |
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
vector<int>h;
bool cmp(int a,int b){ return a>b; }
int n;
int main(){
freopen("algsort.in","r",stdin);
freopen("algsort.out","w",stdout);
scanf("%d",&n);
h.resize(n);
for(int i=0;i<n;i++)scanf("%d",&h[i]);
make_heap(h.begin(),h.end(),cmp);
for(int i=0;i<n;i++)
{
printf("%d ",h[0]);
pop_heap(h.begin(),h.end(),cmp);
h.pop_back();
}
return 0;
}