#include<stdio.h>
int main()
{
int A[] = {2,2,2,1,1,1,0,0,0,1,2,0};
int j,i,x,y,n,t=A[0];
n=sizeof(A)/sizeof(A[0]);
printf("Size of array : %d\n",n);
for(x=i=0,y=j=n-1;i<=j;)
{
if(t==0)
{
A[x]=0;
x++;
i++;
t=A[i];
}
else if(t==2)
{
t=A[y];
A[y]=2;
y--;
j--;
}
else
{
i++;
t=A[i];
}
}
while(x<=y)
{
A[x++]=1;
}
for(i=0;i<n;i++)
{
printf(" %d",A[i]);
}
return 0;
}
Let me know your thoughts.
No comments:
Post a Comment