Created
September 28, 2014 06:16
-
-
Save satveersm/38a0c8a2748e2cf20131 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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