/* 烟台大学计算机学院 作者:任子仪 日期:2013年12月1日 问题描述: 样例输入: 样例输出: 问题分析: */ #include <iostream> using namespace std; //两个函数bubble_sort和output_array的声明 void bubble_sort(int a[],int num); void output_array(int a[],int num); int main( ) { int a[20]= {86,76,62,58,77,85,92,80,96,88,77,67,80,68,88,87,64,59,61,76}; int b[15]= {27,61,49,88,4,20,28,31,42,62,64,14,88,27,73}; bubble_sort(a,20);//用冒泡法按降序排序a中元素 cout<<"数组a的由小到大的排序是:"; output_array(a,20); //输出排序后的数组 cout<<endl; bubble_sort(b,15); //用冒泡法按降序排序b中元素 cout<<"数组b的由小到大的排序是:"; output_array(b,15); //输出排序后的数组 cout<<endl; return 0; } //请在下面定义bubble_sort和output_array函数 void bubble_sort(int a[],int num) { int i,j,t; for(j=0; j<num; j++) for(i=0; i<num-j-1; i++) if(a[i+1]>a[i]) { t=a[i]; a[i]=a[i+1]; a[i+1]=t; } return; } void output_array(int a[],int num) { int i; for(i=0; i<num; i++) cout<<a[i]<<" "; return; }
心得体会:新的月份,新的开始。加油。。。。。。。。