0 at odd places and 1 at even places
C++ Code
#include <iostream>
using namespace std;
void arrange(int a[],int n)
{
int i=0,zero=-1,one=-1;
while(i<n&&zero<n&&one<n)
{
if(i%2!=0) // if odd place
{
if(a[i]!=0)
{
if(zero==-1)
zero=i+1;
while(a[zero]!=0&&zero<n)
zero++;
if(a[zero]==0)
{
a[zero]=1;
a[i]=0;
zero++;
}
}
}
else
{
if(a[i]!=1)
{
if(one==-1)
one=i+1;
while(a[one]!=1&&one<n)
one++;
if(a[one]==1)
{
a[one]=0;
a[i]=1;
one++;
}
}
}
i++;
}
}
int main(int argc, char *argv[])
{
int a[]={1,0,1,1,0,0,1,1,1,0};
int n=10;
arrange(a,n);
for(int i=0;i<n;i++)
cout<<a[i]<<" ";
return EXIT_SUCCESS;
}
i was faced many problems to solve this, a few months ago my professor give me an assignment on this topic, I try to many times but I failed, then I am hired an Assignment Writing Service 24 USA'S, they company completed my work on time, i really happy to take services for this company
ReplyDeleteolky
Delete