Cod sursa(job #2512114)
| Utilizator | Data | 20 decembrie 2019 16:26:52 | |
|---|---|---|---|
| Problema | Sortare prin comparare | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.57 kb |
#include <algorithm>
#include <iterator>
#include <fstream>
using namespace std;
void shell_sort (int *a, int n) {
int h, i, j, t;
for (h = n; h /= 2;) {
for (i = h; i < n; i++) {
t = a[i];
for (j = i; j >= h && t < a[j - h]; j -= h) {
a[j] = a[j - h];
}
a[j] = t;
}
}
}
int main(){
int a[500000],n,i;
ifstream fin("algsort.in");
ofstream fout("algsort.out");
fin>>n;for(i=0;i<n;i++)fin>>a[i];
shell_sort(a,n);
for(i=0;i<n;i++)
fout << a[i]<< " ";
return 0;
}
