C/C++
Задача на Си
Перепишите массив так чтобы элементы с парными индексами были размещены по возрастанию, а с нечетными по убыванию
Вот реализация алгоритма Айрана:
#include <ctime>
#include <cstdlib>
#include <iomanip>
#include <iostream>
using namespace std;
void print(int x[], int size)
{ int i, j = 0; for (i = 0; i < size; i++)
{ ++j; cout << setw(4) << x[i];
if (j == 10) { j = 0; cout << endl; } }
if (j) cout << endl; }
int main()
{ int i, j, n; while (true) {
cout << "\033[34mn: \033[31m";
cin >> n; int *a = new int [n];
srand(time(nullptr));
for (i = 0; i < n; i++) a[i] = rand() % 199 - 99;
cout << "\033[36m"; print(a, n);
for (i = 2; i < n; i += 2)
for (j = (n - 1) / 2 * 2; j >= i; j -= 2)
if (a[j - 2] > a[j]) swap(a[j - 2], a[j]);
for (i = 3; i < n; i += 2)
for (j = n - 1 - n % 2; j >= i; j -= 2)
if (a[j - 2] < a[j]) swap(a[j - 2], a[j]);
cout << "\033[35m"; print(a, n); delete [] a; } }

#include <ctime>
#include <cstdlib>
#include <iomanip>
#include <iostream>
using namespace std;
void print(int x[], int size)
{ int i, j = 0; for (i = 0; i < size; i++)
{ ++j; cout << setw(4) << x[i];
if (j == 10) { j = 0; cout << endl; } }
if (j) cout << endl; }
int main()
{ int i, j, n; while (true) {
cout << "\033[34mn: \033[31m";
cin >> n; int *a = new int [n];
srand(time(nullptr));
for (i = 0; i < n; i++) a[i] = rand() % 199 - 99;
cout << "\033[36m"; print(a, n);
for (i = 2; i < n; i += 2)
for (j = (n - 1) / 2 * 2; j >= i; j -= 2)
if (a[j - 2] > a[j]) swap(a[j - 2], a[j]);
for (i = 3; i < n; i += 2)
for (j = n - 1 - n % 2; j >= i; j -= 2)
if (a[j - 2] < a[j]) swap(a[j - 2], a[j]);
cout << "\033[35m"; print(a, n); delete [] a; } }

взять самую простую сортировку, пузырьком к примеру, заменить все +1 на +2, применить дважды - с разного начала, с возрастанием и убыванием