Segregate 0s and 1s in an array

Description:

You are given an array of 0s and 1s in random order. Segregate 0s on left side and 1s on right side of the array. Traverse array only once. Input array = [0, 1, 0, 1, 0, 0, 1, 1, 1, 0] Output array = [0, 0, 0, 0, 0, 1, 1, 1, 1, 1] Test Case 1 Input (stdin) 6 0 1 0 1 1 1 Expected Output 0 0 1 1 1 1 Test Case 2 Input (stdin) 8 0 1 0 1 1 1 0 0 Expected Output 0 0 0 0 1 1 1 1

Program :

#include <iostream>

using namespace std;

int main()

{

int n,i,s[50],temp,t;

  cin>>n;

  for(i=0;i<n;i++)

    cin>>s[i];

  t=n/2;

  while(t--)

  {

    for(i=0;i<n-1;i++)

      if(s[i]>s[i+1])

      {

      temp=s[i];

        s[i]=s[i+1];

        s[i+1]=temp;

      }}

  for(i=0;i<n;i++)

  cout<<s[i]<<" ";

return 0;

}