1.

Given An Array Of 1s And 0s Arrange The 1s Together And 0s Together In A Single Scan Of The Array. Optimize The Boundary Conditions.?

Answer»

void main()

{

int A[10]={'0','1','0','1','0','0','0','1','0','1','0','0'};

int X=0,y=A.length-1;

while(x if(!A[x])

x++;

ELSE if(A[y])

y--;

if(A[x] && !A[y])//here we are checking that STATING index is having 1 and last index having 0 than swap values

A[x]=0,A[y]=1;

}

getch() 

}

void main()

{

int A[10]={'0','1','0','1','0','0','0','1','0','1','0','0'};

int x=0,y=A.length-1;

while(x if(!A[x])

x++;

else if(A[y])

y--;

if(A[x] && !A[y])//here we are checking that stating index is having 1 and last index having 0 than swap values

A[x]=0,A[y]=1;

}

getch() 

}



Discussion

No Comment Found