This repository has been archived on 2026-07-28. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
cmc/3sem/cnts/contest1/test.c
T
2025-04-13 21:48:15 +03:00

52 lines
892 B
C
Executable File

#include <stdlib.h>
#include <malloc.h>
#include <stdio.h>
int
cmp(const void *a, const void *b)
{
if (*(int *) a % 2 == 0) {
if (*(int *) b % 2 == 1) {
return -1;
}
if (*(int *) a > *(int *) b) {
return 1;
}
if (*(int *) a < *(int *) b) {
return -1;
}
return 0;
}
if (*(int *) b % 2 == 0) {
return 1;
}
if (*(int *) a > *(int *) b) {
return -1;
}
if (*(int *) a < *(int *) b) {
return 1;
}
return 0;
}
void
sort_even_odd(size_t count, int *data)
{
qsort(data, count, sizeof(int), cmp);
}
int
main()
{
int a[] = {4, 2, 5, 3, 1, 0, -4, -2, -68, 23, 3};
sort_even_odd(sizeof(a) / sizeof(a[0]), a);
for (int i = 0; i < sizeof(a) / sizeof(a[0]); i++) {
printf("%d ", a[i]);
}
printf("\n");
return 0;
}