class Solution { public: void reOrderArray(vector<int> &array) //加个&表示引用 { int array_size = array.size(); //int xiabiao = (array_size - 1); vector<int> brray; for (int i = 0; i < array_size; ++i) { brray.push_back(array[i]); } int i = 0; int k = 0; int j = 0; while (i < array_size) { if ((brray[i]) % 2 != 0) { array[k] = brray[i]; ++k; } ++i; } while (j < array_size) { if ((brray[j]) % 2 == 0) { array[k] = brray[j]; ++k; } ++j; } } };
时间: 2024-12-14 11:22:34