标签:
1 class Solution { 2 public: 3 void reOrderArray(vector<int> &array) { 4 5 vector<int> array_temp; 6 vector<int>::iterator ib1, ie1; 7 ib1 = array.begin(); 8 9 10 for (; ib1 != array.end();){ //遇见偶数,就保存到新数组,同时从原数组中删除 11 if (*ib1 % 2 == 0) { 12 array_temp.push_back(*ib1); 13 ib1 = array.erase(ib1); 14 } 15 else{ 16 ib1++; 17 } 18 19 } 20 vector<int>::iterator ib2, ie2; 21 ib2 = array_temp.begin(); 22 ie2 = array_temp.end(); 23 24 for (; ib2 != ie2; ib2++) //将新数组的数添加到老数组 25 { 26 array.push_back(*ib2); 27 } 28 } 29 };
标签:
原文地址:http://www.cnblogs.com/SeekHit/p/5760807.html