// test46.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <iostream> using namespace std; void range(int * a,int len){ int begin=0; while(begin<len && a[begin]%2) begin++; //此时begin定位到第一个偶数上 int temp=a[begin]; int end=len-1; while(begin<end){ while(begin<end && !(a[end]%2) ) end--; a[begin]=a[end]; while(begin<end && a[begin]%2 ) begin++; a[end]=a[begin]; } a[begin]=temp; } void main(){ int a[10]={0,1,2,3,4,5,6,7,8,9}; range(a,10); for(int i=0;i<10;i++) printf("%d/n",a[i]); }