问题如下:
实现代码
- #include<stdio.h>
- #include <stdlib.h>
- void printArray(int array[],int arrayNum)
- {
- for (int i = 0; i < arrayNum; i++)
- {
- printf("%d ", array);
- }
- printf("\n");
- }
- void adjustArray(int array[], int begin, int end)
- {
- int left = begin;
- int right = end;
- while (begin <= end)
- {
- if (array[begin] % 2 == 0)
- {
- begin++;
- }
- else
- {
- while (array[end] % 2 != 0)
- {
- end--;
- }
- if (end <= begin)
- break;
- int temp = array[begin];
- array[begin] = array[end];
- array[end] = temp;
- end--;
- }
- if (array[end] % 2 != 0)
- {
- end--;
- }
- }
- }
- int main()
- {
- int array[] = {12, 31,17,45,68,40,57,43,25,78 };
- int begin = 0;
- int end = 9;
- adjustArray(array, 0, 9);
- printArray(array, 10);
- return 0;
- }
|