项目四-数组的排序

来源:互联网 发布:linux 开机自启动 编辑:程序博客网 时间:2024/06/03 23:39
<pre class="cpp" name="code"> /*  *Copyright (c) 2014, 烟台大学计算机学院  * All right reserved.  * 文件名称:test.cpp    * 作者:赵嵩  * 完成时间:2014年11月12号  * 版本号:v1.0  */

#include<iostream>using namespace std;void bubble_sort(int s[],int n);void output_array(int s[],int n);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);    output_array(a,20);    bubble_sort(b,15);    output_array(b,15);    return 0;}void bubble_sort(int s[],int n){    int i,j,t;    for (j=1; j<=n-1; j++)        for (i=0; i<n-j; i++)        {            if (s[i]<s[i+1])            {                t=s[i];                s[i]=s[i+1];                s[i+1]=t;            }        }}void output_array(int s[],int n){    cout<<"降序后的数组是:";    for (int i=0; i<n; i++)        cout<<s[i]<<" ";    cout<<endl;}

运行结果:


0 0
原创粉丝点击