-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3c691b2
commit bad4f67
Showing
1 changed file
with
50 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#include<iostream> | ||
#include<vector> | ||
using namespace std; | ||
void sortEvenAndOdd(vector <int> &v) | ||
{ | ||
int left_ptr=0; | ||
int right_ptr=v.size()-1; | ||
|
||
while(left_ptr<right_ptr) | ||
{ | ||
if(v[left_ptr] % 2 ==1 && v[right_ptr] % 2 ==0) | ||
{ | ||
int temp=v[left_ptr]; | ||
v[left_ptr]=v[right_ptr]; | ||
v[right_ptr]=temp; | ||
left_ptr++; | ||
right_ptr--; | ||
} | ||
if(v[left_ptr]%2==0) | ||
{ | ||
left_ptr++; | ||
} | ||
if(v[right_ptr]%2==1) | ||
{ | ||
right_ptr--; | ||
} | ||
} | ||
} | ||
|
||
int main() | ||
{ | ||
cout<<"Move all the ven integer at very ist pos and move all thge odd integers at he last of the array/vector:"<<endl; | ||
cout<<"Enter the size of the vector:"<<endl; | ||
int size; | ||
cin>>size; | ||
vector<int> v(size); | ||
cout<<"Enter the values:"<<endl; | ||
for(int i=0;i<size;i++) | ||
{ | ||
cin>>v[i]; | ||
} | ||
sortEvenAndOdd(v); | ||
|
||
cout<<"Output here:"<<endl; | ||
for(int i=0;i<v.size();i++) | ||
{ | ||
cout<<v[i]<<" "; | ||
} | ||
|
||
} |