Cod sursa(job #1085489)
| Utilizator | Data | 17 ianuarie 2014 01:33:22 | |
|---|---|---|---|
| Problema | Sortare prin comparare | Scor | 60 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.56 kb |
#include <fstream>
using namespace std;
int main()
{
ifstream cin("algsort.in");
ofstream cout("algsort.out");
const int gaps[] = { 701, 301, 132, 57, 23, 10, 4, 1 };
int n;
cin >> n;
int *a = new int[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (const int &gap : gaps) {
int i, j, temp;
for (i = gap; i < n; i++) {
temp = a[i];
for (j = i; j >= gap && a[j - gap] > temp; j -= gap) {
a[j] = a[j - gap];
}
a[j] = temp;
}
}
for (int i = 0; i < n; i++) {
cout << a[i] << " ";
}
return 0;
}