#include<iostream> //奇数在前 偶数在后
using namespace std;
void swap(double *dPara1, double *dPara2)
{
double temp = 0.0;
temp = *dPara1;
*dPara1 = *dPara2;
*dPara2 = temp;
}
void move( int arr[], int len)
{
int i=0, j=len-1;
while(i<j)
{
while(i<j&&arr[i]%2!=0) i++;
while(i<j&&arr[j]%2==0) j--;
if(i<j)
{
swap(arr[i], arr[j]);
i++;
j--;
}
}
}
int main()
{
int arr[9] = { 1, 2, 3, 4, 5, 6, 7, 8, 9};
move( arr, 9);
for( int i=0; i<=8; i++)
{
cout<<arr[i]<<" ";
}
cout<<endl;
return 0;
}
快速排序的演变
最新推荐文章于 2022-04-27 20:54:57 发布