#include <stdio.h>void sort (int *p, int len) {int *end = P;end = p + len-1;while (p<end) {if (*p% 2 = = 0) {while ( End) {if (*end% 2 = = 1) {break;} end--;} int tmp = *end;*end = *p;*p = tmp;p++;} else{p++;}}} int main () {int arr[] = {3,5,4,8,9,5,6,2,6};int len = sizeof (arr)/sizeof (arr[0]), sort (arr,len); int i = 0;for (i = 0; I & Lt Len i++) {printf ("%d", Arr[i]);} return 0;} Output as 3,5,5,9,8,4,6,2,6 This problem my idea is to set two marks, a point to the head of a point to the tail, the first element if it is an odd number regardless of him, if it is an even number and the last comparison, which is if the tail element is an odd number of the interchange or the trailing element moves forward, Until the odd number is found, loop in turn until two signs meet to stop.
This article is from the "Traces" blog, be sure to keep this source http://wpfbcr.blog.51cto.com/10696766/1710465
Adjust array so that all odd numbers are in front of even numbers