class Solution {
public:
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param array int整型vector
* @return int整型vector
*/
vector<int> reOrderArray(vector<int>& array) {
// write code here
return Sort(array);
}
/*方法1:暴力枚举*/
vector<int> reorderArray(vector<int> array){
vector<int> result;vector<int>::iterator it = array.begin();
vector<int> temp;
while(it != array.end()){
if(*it%2 != 0){
result.push_back(*it);
}else{
temp.push_back(*it);
}
it++;
}it = temp.begin();
while(it != temp.end()){
result.push_back(*it);it++;
}return result;
}
/*方法2: 重定位函数重载*/
vector<int> Sort(vector<int>& array){
auto cmpFuncation = [](int a){
return a%2 != 0;
};stable_partition(array.begin(),array.end(),cmpFuncation);
return array;
}
};