Title: Enter an array of shapes, reorder the arrays so that all the odd numbers are in the front even, and the relative positions between the odd and the even are not changed.
Thought: Iterates through all arrays starting at the beginning of the array. When an even number is encountered, the even is packaged, that is, the count of the even numbers so far, and these even as a whole, and when an odd number is encountered, the odd point is swapped with the previous even integer.
#include <stdio.h> #include <stdlib.h>void nuo (INT&NBSP;*A,INT&NBSP;J,INT&NBSP;NU) //the odd and all the even swapped positions in front { int b=a[j]; while (nu--) { a[j]=a[j-1]; j--; } a[j]=b;} Int main () { int* a; int i = 0 ; int j = 0 ; int nu= 0 ; printf ("Enter the number of arrays: \ n"), scanf ("%d", &i), A=malloc (sizeof (int) *i);p rintf ("Please enter an array separated by commas: \ n"); for (; j<i;j++) { scanf ("%d,", &a[j]);} J=0; while (I!=J) { if (a[j]%2==1) { //This number is odd nuo (A,J,NU); j++; } else{ //When this number is an even number, record even numbers j++; nu+=1; } } printf ("a[%d]=", I); j=0; while (i!=j ) {&NBSP;&NBSP;&NBSP;&NBSP;&Nbsp; printf (" %d", a[j++]); } printf ("\ n"); return 0;}
This article is from the "Ling Feng 2019" blog, be sure to keep this source http://lingfeng2019.blog.51cto.com/12741667/1910061
The "algorithm" adjusts the order of the array so that the odd and even positions are unchanged after the first even number.