提高第27课时,实践3,项目3-数组的排序
来源:互联网 发布:sqlserver 默认值约束 编辑:程序博客网 时间:2024/06/04 17:56
/**Copyright(c) 2015/5/18 CSDN博客*All rights reserved.*文件名称:main.c*作 者:金叶*完成日期:2015/5/18*版本号:V1.0*问题描述:项目3 - 数组的排序d(1)编写函数,完成冒泡排序要求不能改变下面的main函数。*/#include <stdio.h>//两个函数bubble_sort和output_array的声明void bubble_sort(int a[],int m);void output_array(int a[],int m);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中元素 output_array(a,20); //输出排序后的数组 bubble_sort(b,15); //用冒泡法按降序排序b中元素 output_array(b,15); //输出排序后的数组 return 0;}//请在下面定义bubble_sort和output_array函数void bubble_sort(int a[],int m){ int i,j; for (i=0;i<m-1;i++){ for (j=0;j<m-i-1;j++){ if (a[i]>a[j]){ int t; t=a[i]; a[i]=a[j]; a[j]=t; } } }}void output_array(int a[],int m){ int i; for (i=0;i<m;i++){ printf("%d\t",a[i]); if ((i+1)%5==0) printf("\n"); } printf("\n");}
/**Copyright(c) 2015/5/18 CSDN博客*All rights reserved.*文件名称:main.c*作 者:金叶*完成日期:2015/5/18*版本号:V1.0*问题描述:(2)字符数组排序:改造(1)的程序,使其能对字符数组进行排序,其中:*/#include <stdio.h>//两个函数bubble_sort和output_array的声明void bubble_sort(char a[],int m);void output_array(char a[],int m);int main( ){ char a[20] = {'s','o','r','t','b','u','b','b','l','e','s','e','l','e','c','t','o','k','o','k'}; char b[15] = {'u','b','b','l','e','s','e','l','e','c','t','o','k','o','k'}; bubble_sort(a,20); //用冒泡法按降序排序a中元素 output_array(a,20); //输出排序后的数组 bubble_sort(b,15); //用冒泡法按降序排序b中元素 output_array(b,15); //输出排序后的数组 return 0;}//请在下面定义bubble_sort和output_array函数void bubble_sort(char a[],int m){ int i,j; for (i=0;i<m-1;i++){ for (j=0;j<m-i-1;j++){ if (a[j]<a[j+1]){ char t; t=a[j]; a[j]=a[j+1]; a[j+1]=t; } } }}void output_array(char a[],int m){ int i; for (i=0;i<m;i++){ printf("%c\t",a[i]); if ((i+1)%5==0) printf("\n"); } printf("\n");}
/**Copyright(c) 2015/5/18 CSDN博客*All rights reserved.*文件名称:main.c*作 者:金叶*完成日期:2015/5/18*版本号:V1.0*体验选择排序:改造(1)的程序,将bubble_sort(...)改为select_sort(...),排序算法由冒泡排序换作为选择排序,排序结果由降序变为升序,完成类似的任务。*/#include <stdio.h>//两个函数bubble_sort和output_array的声明void select_sort(int a[],int m);void output_array(int a[],int m);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}; select_sort(a,20); //用冒泡法按降序排序a中元素 output_array(a,20); //输出排序后的数组 select_sort(b,15); //用冒泡法按降序排序b中元素 output_array(b,15); //输出排序后的数组 return 0;}//请在下面定义bubble_sort和output_array函数void select_sort(int a[],int m){ int i,j,k,t; for (i=0;i<m-1;i++){ k=i; for (j=i+1;j<m;j++){ if (a[j]<a[k]){ k=j; } } t=a[k]; a[k]=a[i]; a[i]=t; }}void output_array(int a[],int m){ int i; for (i=0;i<m;i++){ printf("%d\t",a[i]); if ((i+1)%5==0) printf("\n"); } printf("\n");}
0 0
- 提高第27课时,实践3,项目3-数组的排序
- 提高第39课时,实践3,项目3-为动态数组扩容
- 提高第31课时,实践3,项目3-字符串复制
- 提高第36课时,实践3,项目3-各种“棋盘”
- 提高第38课时,实践3,项目3 - 命令行加法器
- 提高第39课时,实践2,项目2-动态数组排序
- 提高第24课时,实践1,项目1-翻转数组
- 提高第21课时,实践4,工资的排序
- 提高第18课时,实践3,当年第几天(数组方案)
- 提高第21课时,实践3,有序数组中插入数据 (第2种方法)
- 提高第21课时,实践3,有序数组中插入数据
- 提高第26课时,实践1,项目1-有序数组中插入数据(函数版)
- 提高第26课时,实践2,项目2 - 删除数组元素
- 提高第34课时,实践1,【项目1-二维数组当函数参数】
- 提高第3课时,自测
- 提高第18课时,实践1,数组大作战
- 提高第21课时,实践1,项目1-有几个
- 提高第39课时,实践1,项目1-学生人数没个准
- 详解JavaScript模块化开发
- 第十一周阅读程序(3)
- 鸡啄米vc++2010系列23(列表框控件ListBox)
- Html5在Android开发中的应用
- Java中LinkedList和ArrayList的区别
- 提高第27课时,实践3,项目3-数组的排序
- matlab对音频均匀量化
- 关于python IDE中中文报错的解决办法
- VMWare虚拟机下为Ubuntu 12.04.1配置静态IP(NAT方式)
- 写个较通用的32位apihook函数 免得每次都重写
- 素数距离问题(nyoj24)
- java过滤器和监听器详解
- openframeworks的阅读及总结(1)
- 洛阳治疗早泄哪家医院好呢~~