2020-05-29 23:23:24 +03:00
|
|
|
#include <stdbool.h>
|
2016-08-05 21:04:35 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
bool check_sorted(int *a, int n)
|
|
|
|
{
|
2020-05-29 23:23:24 +03:00
|
|
|
while (--n >= 1)
|
|
|
|
{
|
|
|
|
if (a[n] < a[n - 1])
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
2016-08-05 21:04:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void shuffle(int *a, int n)
|
|
|
|
{
|
2020-05-29 23:23:24 +03:00
|
|
|
int i, t, r;
|
|
|
|
for (i = 0; i < n; i++)
|
|
|
|
{
|
|
|
|
t = a[i];
|
|
|
|
r = rand() % n;
|
|
|
|
a[i] = a[r];
|
|
|
|
a[r] = t;
|
|
|
|
}
|
2016-08-05 21:04:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void sort(int *a, int n)
|
|
|
|
{
|
2020-06-28 18:25:37 +03:00
|
|
|
while (!check_sorted(a, n)) shuffle(a, n);
|
2016-08-05 21:04:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
2020-05-29 23:23:24 +03:00
|
|
|
int numbers[6];
|
|
|
|
int i;
|
|
|
|
printf("Enter 6 numbers unsorted \n\n");
|
|
|
|
for (i = 0; i < 6; i++)
|
|
|
|
{
|
|
|
|
scanf("%d", &numbers[i]);
|
|
|
|
}
|
|
|
|
sort(numbers, 6);
|
2020-06-28 18:25:37 +03:00
|
|
|
for (i = 0; i < 6; i++) printf("%d ", numbers[i]);
|
2020-05-29 23:23:24 +03:00
|
|
|
printf("\n");
|
2016-08-05 21:04:35 +03:00
|
|
|
}
|