Skip to content

Instantly share code, notes, and snippets.

@satveersm
Created September 28, 2014 06:16
Show Gist options
  • Save satveersm/38a0c8a2748e2cf20131 to your computer and use it in GitHub Desktop.
Save satveersm/38a0c8a2748e2cf20131 to your computer and use it in GitHub Desktop.
#include<iostream>
#include<string.h>
#include<stack>
#include<vector>
using namespace std;
int main()
{
int num = 8;
std::vector<int> v;
int x;
for(int i = 0; i < num; i++)
{
cin>>x;
v.push_back(x);
}
int low = 0;
int high = num-1;
while(low < high)
{
if(v[low]%2 == 0)
{
low++;
}
else if(v[high]%2 == 1)
{
high--;
}
else
{
int temp = v[low];
v[low] = v[high];
v[high] = temp;
low++;
high--;
}
}
for(int i = 0; i < num; i++)
{
cout<<v[i]<<" ";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment