2017-05-04 21:21:39 +03:00
|
|
|
#include <stdio.h>
|
2020-04-24 03:45:45 +03:00
|
|
|
#include <stdlib.h>
|
2017-05-04 21:21:39 +03:00
|
|
|
|
2020-04-24 03:45:45 +03:00
|
|
|
void swap(int *a, int *b)
|
|
|
|
{
|
2017-05-04 21:21:39 +03:00
|
|
|
int temp;
|
|
|
|
temp = *a;
|
|
|
|
*a = *b;
|
|
|
|
*b = temp;
|
|
|
|
}
|
2020-04-24 03:45:45 +03:00
|
|
|
void shakersort(int *a, int n)
|
2017-05-04 21:21:39 +03:00
|
|
|
{
|
|
|
|
int p, i;
|
|
|
|
for (p = 1; p <= n / 2; p++)
|
|
|
|
{
|
|
|
|
for (i = p - 1; i < n - p; i++)
|
2020-04-24 03:45:45 +03:00
|
|
|
if (a[i] > a[i + 1])
|
|
|
|
{
|
2017-05-04 21:21:39 +03:00
|
|
|
swap(&a[i], &a[i + 1]);
|
2020-04-24 03:45:45 +03:00
|
|
|
}
|
2017-05-04 21:21:39 +03:00
|
|
|
for (i = n - p - 1; i >= p; i--)
|
2020-04-24 03:45:45 +03:00
|
|
|
if (a[i] < a[i - 1])
|
|
|
|
{
|
2017-05-04 21:21:39 +03:00
|
|
|
swap(&a[i], &a[i - 1]);
|
2020-04-24 03:45:45 +03:00
|
|
|
}
|
2017-05-04 21:21:39 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
int n;
|
2020-04-24 03:45:45 +03:00
|
|
|
scanf("%d", &n);
|
|
|
|
int *arr = (int *)malloc(n * sizeof(int));
|
|
|
|
int i;
|
2020-06-28 18:25:37 +03:00
|
|
|
for (i = 0; i < n; i++) scanf("%d ", &arr[i]);
|
2017-05-04 21:21:39 +03:00
|
|
|
shakersort(arr, n);
|
2020-06-28 18:25:37 +03:00
|
|
|
for (i = 0; i < n; i++) printf("%d ", arr[i]);
|
2020-04-24 03:45:45 +03:00
|
|
|
free(arr);
|
2017-05-04 21:21:39 +03:00
|
|
|
return 0;
|
|
|
|
}
|