标签:include
#include<stdio.h> #include<assert.h> void ReorderOddEven(int arry[], int size) { assert(arry); if (arry == NULL || size <= 0) { return; } int begin = 0; int temp = 0; int end = size - 1; while (begin<end) { while (begin<end && arry[begin] % 2 != 0) //向后移动begin,直到它指向偶数 { begin++; } while (begin<end && arry[end] % 2 == 0) // 向前移动pEnd,直到它指向奇数 { end--; } if (begin<end) { temp = arry[begin]; // 交换偶数和奇数 arry[begin] = arry[end]; arry[end] = temp; } } for (int j = 0; j<size; j++) { printf("%d", arry[j]); } } int main() { int arr[] = { 1,2,3,4,5,6,7,8 }; int size = sizeof(arr) / sizeof(arr[0]); ReorderOddEven(arr, size); system("pause"); return 0; }
标签:include
原文地址:http://10738432.blog.51cto.com/10728432/1713265