第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; }
心得体会:一定多思考,想了又想,别怕多想。
相关文章推荐
- 第14周项目9-字符数组排序
- 第14周项目4数组的排序
- C++第14周项目4——数组的排序
- C++第14周项目4——数组的排序
- 第14周项目4--数组的排序
- 第14周项目4--拓展一--字符数组排序
- 提高项目25.2-数组排序(字符)
- 第14周 项目2 - 二叉树排序树中查找的路径
- 第14周项目1-(3)二叉树排序树的相关算法
- 第14周项目一 数组大折腾
- 第14周项目2-二叉树排序树中查找的路径
- 第17周项目-数组的排序
- 【第14周 项目2 - 二叉树排序树中查找的路径】
- 第16周项目 1 数组的排序
- 第十三周项目4-数组的排序:冒泡排序
- 第16周项目1数组的排序
- 第16周项目1-数组的排序
- 第十三周 项目四:数组的排序(1.1)
- 第十六周 项目一--数组的排序(指针&冒泡)
- 【数组】14周项目四(一)。字符数组排序