本题要求实现三个函数,将整数数组中的最小值和最大值交换到下标最小和下标最大的位置。要求用最少的扫描趟数,最少的交换次数(数组内的数据交换,必须调用指定的数据交换函数以统计实际交换的次数)。
需要实现的函数接口定义:
int CreatA(int st[]);
函数CreatA的功能是输入若干整数为数组st赋值,输入的各个整数用空格分隔,输入-1结束赋值。函数返回值为整型数组元素个数。
int Maxmin(int st[],int n);
Maxmin函数筛选有n个元素的数组st中的最小值、最大值,并将最小值移动到最小下标,最大值移动到最大下标,要求移动元素次数最少,两个元素的互换按一次交换计算,返回值为交换次数。
void Output(int st[],int n);
Output函数用于输出整型数组,数组元素个数为n,输出数据用逗号分隔。
裁判测试程序样例:
#include
int CreatA(int st[]);
int Maxmin(int st[],int n);
void output(int st[],int n);
void swap(int st[],int i,int j)//d[i]<-->d[j]//数组内的数据交换函数,交换最小最大值位置时必须调用,i、j为下标
{
int temp;
temp=st[i];st[i]=st[j];st[j]=temp;
}
int main()
{
int st[88],n,num;
n=CreatA(st);
num=Maxmin(st,n);
output(st,n);
printf("%dn",num);
return 0;
}
输入样例:
12 88 37 54 62 -1
12 88 37 54 62 -1
结尾无空行
输出样例:
12,62,37,54,88
1
结尾无空行
输入样例:
45 87 42 65 23 -1
结尾无空行
输出样例:
23,45,42,65,87
2
结尾无空行



