问:将数组按照先排奇数再排偶数的顺序排列
#define _CRT_SECURE_NO_WARNINGS 1 #include <stdio.h> void move(int arr[], int sz) { int lift = 0; int right = sz - 1; while (lift < right) { while ((lift < right) && (arr[lift] % 2 == 1)) { lift++; } while ((lift < right) && (arr[right] % 2 == 0)) { right--; } if (lift < right) { int tmp = arr[lift]; arr[lift] = arr[right]; arr[right] = tmp; } } } void print(int arr[],int sz) { int i = 0; for (i = 0; i < sz; i++) { printf("%d", arr[i]); } printf("\n"); } int main() { int arr[] = { 1,2,3,7,9 }; int sz = sizeof(arr) / sizeof(arr[0]); move(arr,sz); print(arr, sz); return 0; }
标签:sz,arr,right,语言,int,代码,练习,while,lift From: https://www.cnblogs.com/ayue6/p/17783070.html