您的位置:首页 > 其它

第14周项目8-数组的排序

2013-11-30 10:35 295 查看
/*
* 程序的版权和版本声明部分
* Copyright (c)2013, 烟台大学计算机学院学生
* All rightsreserved.
* 文件名称: fibnacci.cpp
* 作    者: 孔云
* 完成日期:2013年11月30日
* 版 本 号: v1.0
* 输入描述:无
* 问题描述:编函数,完成冒泡排序。
* 程序输出:已排序的数组中元素值。
* 问题分析:在利用函数的条件下完成。
*/
#include <iostream>
using namespace std;
void bubble_sort(int a[],int n);
void output_array(int b[],int m);//两个函数bubble_sort和output_array的声明
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};
cout<<"排序后的数组a[i]是:"<<endl;
bubble_sort(a,20);//用冒泡法按降序排序a中元素
output_array(a,20);//输出排序后的数组
cout<<"排序后的数组b[i]是:"<<endl;
bubble_sort(b,15);//用冒泡法按降序排序b中元素
output_array(b,15);//输出排序后的数组

return 0;
}
void  bubble_sort(int s[],int t)//请在下面定义bubble_sort和output_array函数
{
int i,k,x;
for(k=0; k<t; k++)
for(i=0; i<t-k; i++)
if(s[i]>s[i+1])
{
x=s[i];
s[i]=s[i+1];
s[i+1]=x;
}
}
void output_array(int s[],int t)
{
int i;
for(i=t-1; i>=0; i--)
cout<<s[i]<<" ";
cout<<endl;
}




心得体会:一定多思考,想了又想,别怕多想。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: