#include <stdio.h>
#include <malloc.h>
#define FIN "algsort.in"
#define FOUT "algsort.out"
struct Arr {
int size;
int *data;
};
typedef struct Arr Arr;
Arr* Array(int size) {
Arr
* v
= (Arr
*)malloc(sizeof(Arr
) * size
);
v
->data
= (int*)malloc(sizeof(int) * size
);
v->size = size;
for (int i = 0; i < size; ++i)
{
v->data[i] = 0;
}
return v;
}
void run_combo(Arr *v) {
float shrinkFactor = 1.3;
int gap = v->size,
count = v->size,
swapped = 0,
i;
while(gap > 1 || swapped) {
swapped = 0;
if(gap > 1) gap = gap/shrinkFactor;
for (int i = 0; (i + gap) < count; ++i)
{
if(v->data[i] > v->data[i+gap]) {
int holder = v->data[i];
v->data[i] = v->data[i+gap];
v->data[i+gap] = holder;
swapped = 1;
}
}
}
}
void display(Arr* arr) {
//freopen(FOUT, "w", stdout);
int count = arr->size;
for (int i = 0; i < count; ++i)
{
printf("%d ", arr
->data
[ i
]); }
}
int main(int argc, char const *argv[])
{
int n;
//freopen(FIN, "r", stdin);
Arr* v = Array( n );
for (int i = 0; i < n; ++i)
{
scanf("%d", &v
->data
[i
]); }
run_combo(v);
display(v);
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxtYWxsb2MuaD4KI2RlZmluZSBGSU4gImFsZ3NvcnQuaW4iCiNkZWZpbmUgRk9VVCAiYWxnc29ydC5vdXQiCgpzdHJ1Y3QgQXJyIHsKICAgICAKICAgICAgICAgICBpbnQgc2l6ZTsKICAgICAgICAgICBpbnQgKmRhdGE7Cn07Cgp0eXBlZGVmIHN0cnVjdCBBcnIgQXJyOwoKQXJyKiBBcnJheShpbnQgc2l6ZSkgewoKICAgICBBcnIqIHYgPSAoQXJyKiltYWxsb2Moc2l6ZW9mKEFycikgKiBzaXplKTsgICAgICAKCiAgICAgICAgICB2LT5kYXRhID0gKGludCopbWFsbG9jKHNpemVvZihpbnQpICogc2l6ZSk7IAoKICAgICAgICAgIHYtPnNpemUgPSBzaXplOwoKICAgICAgICAgIGZvciAoaW50IGkgPSAwOyBpIDwgc2l6ZTsgKytpKQoJICAgICAgewoJIAkgICAgICAgdi0+ZGF0YVtpXSA9IDA7CgkgICAgICB9CgogICAgICAgICAgcmV0dXJuIHY7Cn0KCnZvaWQgcnVuX2NvbWJvKEFyciAqdikgewoKCSBmbG9hdCBzaHJpbmtGYWN0b3IgPSAxLjM7CgkgaW50IGdhcCA9IHYtPnNpemUsIAoJICAgICBjb3VudCA9IHYtPnNpemUsCgkgICAgIHN3YXBwZWQgPSAwLCAKCSAgICAgaTsKCgkgICAgIHdoaWxlKGdhcCA+IDEgfHwgc3dhcHBlZCkgewoKCSAgICAgCSAgIHN3YXBwZWQgPSAwOwoKCSAgICAgCSAgIGlmKGdhcCA+IDEpIGdhcCA9IGdhcC9zaHJpbmtGYWN0b3I7CgoJICAgICAJICAgZm9yIChpbnQgaSA9IDA7IChpICsgZ2FwKSA8IGNvdW50OyArK2kpCgkgICAgIAkgICB7CgkgICAgIAkgICAJICAgIGlmKHYtPmRhdGFbaV0gPiB2LT5kYXRhW2krZ2FwXSkgewoKCSAgICAgICAgICAgICAgICAgICAgaW50IGhvbGRlciA9IHYtPmRhdGFbaV07CgkgICAgICAgICAgICAgICAgICAgIAoJICAgICAgICAgICAgICAgICAgICB2LT5kYXRhW2ldID0gdi0+ZGF0YVtpK2dhcF07CgkgICAgICAgICAgICAgICAgICAgIAoJICAgICAgICAgICAgICAgICAgICB2LT5kYXRhW2krZ2FwXSA9IGhvbGRlcjsKCSAgICAgICAgICAgICAgICAgICAgCgkgICAgICAgICAgICAgICAgICAgIHN3YXBwZWQgPSAxOwoJICAgICAgICAgICAgICAgIH0gICAgCgkgICAgIAkgICB9CiAgICAgICAgIH0KCn0KCnZvaWQgZGlzcGxheShBcnIqIGFycikgewoKICAgICAvL2ZyZW9wZW4oRk9VVCwgInciLCBzdGRvdXQpOwoKICAgICBpbnQgY291bnQgPSBhcnItPnNpemU7CgoJIGZvciAoaW50IGkgPSAwOyBpIDwgY291bnQ7ICsraSkKCSB7CgkgCSBwcmludGYoIiVkICIsIGFyci0+ZGF0YVsgaSBdKTsKCSB9Cn0KCgppbnQgbWFpbihpbnQgYXJnYywgY2hhciBjb25zdCAqYXJndltdKQp7CglpbnQgbjsKCgkvL2ZyZW9wZW4oRklOLCAiciIsIHN0ZGluKTsKCglzY2FuZigiJWQiLCAmbik7CgoJQXJyKiB2ID0gQXJyYXkoIG4gKTsKCgkgICAgIGZvciAoaW50IGkgPSAwOyBpIDwgbjsgKytpKQoJICAgICB7CgkgICAgIAlzY2FuZigiJWQiLCAmdi0+ZGF0YVtpXSk7CgkgICAgIH0KCiAgICAgICAgIHJ1bl9jb21ibyh2KTsKCgkgICAgIGRpc3BsYXkodik7CgoJcmV0dXJuIDA7Cn0=