-
Notifications
You must be signed in to change notification settings - Fork 0
/
sortingWithout.c
53 lines (53 loc) · 880 Bytes
/
sortingWithout.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <stdio.h>
int main()
{
int a[] = {0, 1, 2, 1, 0, 2, 1};
int c1 = 0;
int c2 = 0;
int c3 = 0;
// printf("%d\n", length);
for (int i = 0; i < 7; i++)
{
printf("%d ", a[i]);
}
for (int i = 0; i < 7; i++)
{
if (a[i] == 0)
{
c1++;
}
else if (a[i] == 1)
{
c2++;
}
else if (a[i] == 2)
{
c3++;
}
}
printf("\n");
// int arr[7];
for (int i = 0; i < 7; i++)
{
if (c1 != 0)
{
a[i] = 0;
c1--;
}
else if (c2 != 0)
{
a[i] = 1;
c2--;
}
else if (c3 != 0)
{
a[i] = 2;
c3--;
}
}
for (int i = 0; i < 7; i++)
{
printf("%d ", a[i]);
}
return 0;
}