Pagini recente » Cod sursa (job #902223) | Cod sursa (job #1477742)
#include <bits/stdc++.h>
using namespace std;
void shell_sort(int A[], int n)
{
const int gaps[] = {1, 2, 4, 8, 21, 56, 149, 404, 1098, 2982, 8104, 22027, 59875, 162756, 442414};
for (int p = 14; p >= 0; p--)
{
int gap = gaps[p];
for (int i = gap; i < n; ++i)
{
int temp = A[i];
int j = i;
while (j >= gap && A[j - gap] > temp)
{
A[j] = A[j - gap];
j -= gap;
}
A[j] = temp;
}
}
}
const int MAX_N = 500000 + 1;
int A[MAX_N];
int N;
int main()
{
ifstream in("algsort.in");
ofstream out("algsort.out");
in >> N;
for (int i = 0; i < N; ++i)
in >> A[i];
shell_sort(A, N);
for (int i = 0; i < N; ++i)
out << A[i] << " ";
return 0;
}