#include "iostream"
using namespace std;
void reOrder(int *data,int length)
{
if (data == NULL || length <= 0)
return;
int* start = data;
int *end = data + length - 1;
while (start<end)
{
while (start<end&&(*start & 1) != 0)
start++;
while (start<end&&(*end & 1) == 0)
end--;
if (start < end)
{
int temp = *start;
*start = *end;
*end = temp;
}
}
}
int main()
{
int ia[] = {1,2,3,4,5};
reOrder(ia, 5);
for (int i = 0; i < 5;i++)
{
cout << ia[i] << endl;
}
system("pause");
return 0;
}
剑指offer面试题14:调整数组顺序使奇数位于偶数前面
最新推荐文章于 2024-05-05 09:49:22 发布