/*
*Copyright (c) 2014,烟台大学计算机学院void change(int a[8][8]);
*All rights reserved.
*文件名称:main.cpp
*作者:苏强
*完成日期:2014年12月14日
*版本号:v1.0
*
*问题描述:用指针给数组排序
*输入描述:无
*程序输出:按照降序排列的数组
*/
#include <iostream>
using namespace std;
void sort(int *p, int num); //不要对自定义函数的声明有任何改动
void output(int*, int); //形式参数的名称可以不要
int main( ) //不要对main函数有任何改动
{
int a[20]= {86,46,22,18,77,45,32,80,26,88,57,67,20,18,28,17,54,49,11,16};
int b[15]= {27,61,49,88,4,20,28,31,42,62,64,14,88,27,73};
sort(a,20); //用冒泡法按降序排序a中元素
output(a,20); //输出排序后的数组
cout<<endl;
sort(b,15); //用冒泡法按降序排序b中元素
output(b,15); //输出排序后的数组
return 0;
}
void sort(int *p, int num) //不要对自定义函数的声明有任何改动
{
int i,j;
char t;
for(i=0; i<num; i++)
for(j=0; j<num-i-1; j++)
{
if(*(p+j)<*(p+j+1))
{
t=*(p+j);
*(p+j)=*(p+j+1);
*(p+j+1)=t;
}
}
return;
}
void output(int *p, int n) //形式参数的名称可以不要
{
int i=0;
while(i<n)
cout<<p[i++]<<" ";
}