#include "stdafx.h"
using namespace std;
#include <string>
#include <vector>
#include <deque>
class Solution
{
public:
Solution();
~Solution();
// [3, 4, 5, 1, 2]
// [1, 2, 3, 4, 5]
// 不能使用左边数与中间数比较,这种做法不能有效地减治
// [1, 2, 3, 4, 5]
// [3, 4, 5, 1, 2]
// [2, 3, 4, 5 ,1]
//push_back用于在尾部插入数据,push_front用于在头部插入数据
void find(vector<int> vec)
{
//vector<int>cc = { 3, 4, 5, 1, 2 }; 4,5,1,2,3
deque <int> deq;
for (int i = 0; i < vec.size(); i++)
{
if (vec[i]%2==0)
{
deq.push_back(vec[i]);
//偶数后插入
}
else if (vec[i]%2==1)
{
deq.push_front(vec[i]);
//奇数前插入
}
}
vec.assign(deq.begin(), deq.end());
}
private:
};
int main()
{
vector<int> aa = { 1, 2, 3, 4, 5 };
vector<int> bb = { 2, 3, 4, 5, 1 };
vector<int>dd = { 4, 5, 1, 2, 3 };
vector<int>cc = { 3, 4, 5, 1, 2 };
Solution sou;
sou.find(cc);
}