Cod sursa(job #721838)
| Utilizator | Data | 24 martie 2012 11:56:45 | |
|---|---|---|---|
| Problema | Algoritmul lui Dijkstra | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.54 kb |
#include <stdio.h>
#include <vector>
#include <algorithm>
std::vector<int>v;
bool cmp(int a,int b){ return a>b?1:0; }
int main(){
int n,x;
freopen("algsort.in","r",stdin);
freopen("algsort.out","w",stdout);
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d",&x);
v.push_back(x); }
make_heap(v.begin(),v.end(),cmp);
for(;v.size()>0;){
printf("%d ",v[0]);
pop_heap(v.begin(),v.end(),cmp);
v.pop_back();
make_heap(v.begin(),v.end(),cmp); }
}
