例如:若a所指数组中的数据最初排列为:9,1,4,2,3,6,5,8,7;按规则移动后,数据排列为:1,9,2,8,3,7,4,6,5。形参n中存放a所指数组中数据的个数。
规定fun函数中的max存放的当前所找的最大值,px存放当前所找最大值得下标。 请在程序的下画线处填入正确的内容并将下画线删除,使程序得出正确的结果。
#include <stdio.h> #define N 9 void fun(int a[], int n) { int i, j, max, min, px, pn, t; for (i = 0; i < n - 1; i += 2) { max = min = __; px = pn = i; for (j = i + 1; j < n; j++) { if (max < __) { max = a[j]; px = j; } if (min > __) { min = a[j]; pn = j; } } if (pn != i) { t = a[i]; a[i] = min; a[pn] = t; if (px == i) px = pn; } if (px != i + 1) { t = a[i + 1]; a[i + 1] = max; a[px] = t; } } } int main() { int b[N] = {9, 1, 4, 2, 3, 6, 5, 8, 7}; printf("\nThe original data:\n"); for (int i = 0; i < N; i++) printf("% 4d", b[i]); printf("\n"); fun(b, N); printf("\nThe data after mocinng \n"); for (int i = 0; i < N; i++) printf("% 4d", b[i]); printf("\n"); return 0; }