-
Notifications
You must be signed in to change notification settings - Fork 1
/
Even_Swap.c
54 lines (52 loc) · 1.11 KB
/
Even_Swap.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
54
#include <stdio.h>
void sort(int a[],int s, int e){
int temp;
for (int i = s; i < e; i++)
{
for (int j = s; j < e; j++)
{
if(a[j]<a[j+1]){
temp = a[j];
a[j] = a[j+1];
a[j+1] = temp;
}
}
}
}
int main()
{
int a[] = {4,6,8,7,3,21,100,98};
int n = 8;
int j=0;
for (int i = 0; i < n;)
{
if (a[i]%2==0)
{
j=i;
while (a[j]%2==0 && j<n)
{
j++;
}
// printf("%d %d\n",i,j);
sort(a,i,j-1);
i=j;
}
else
{
j=i+1;
while (a[j]%2==1 && j<n)
{
j++;
}
sort(a,i,j-1);
// printf("%d %d\n",i,j-1);
i=j;
}
}
for (int k = 0; k < n; k++)
{
printf("%d ",a[k]);
}
printf("\n");
return 0;
}