第十三周项目四数组的排序(2)
2014-11-23 14:39
274 查看
问题及代码:
运行结果:
知识点总结:
要在开始写#include <cstdio>
学习心得:
第一个写出来之后,这个就简单多了,把一些地方稍微改一下就可以了。
/* * Copyright (c) 2014, 烟台大学计算机学院 * All rights reserved. * 文件名称:test.cpp * 作 者:郝俊宇 * 完成日期:2014年 11 月 23 日 * 版 本 号:v1.0 * * 问题描述:字符数组排序:改造(1)的程序,使其能对字符数组进行排序 * 输入描述:无 * 程序输出:对应的数 */ #include <iostream> #include <cstdio> using namespace std; void bubble_sort(char d[],int n); void output_array(char d[],int n); 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]= {'a','d','f','r','g','r','y','y','e','u','i','i','p','o','q'}; bubble_sort(a,20); output_array(a,20); bubble_sort(b,15); output_array(b,15); return 0; } void bubble_sort(char d[],int n) { int i,j; char t; for(i=0;i<n-1;++i) for(j=0;j<n-1-i;++j) if(d[j]<d[j+1]) { t=d[j]; d[j]=d[j+1]; d[j+1]=t; } return; } void output_array(char d[],int n) { int i; for(i=0;i<n-1;++i) cout<<d[i]<<","; cout<<d[n-1]<<" "; cout<<endl; return ; }
运行结果:
知识点总结:
要在开始写#include <cstdio>
学习心得:
第一个写出来之后,这个就简单多了,把一些地方稍微改一下就可以了。
相关文章推荐
- 第十三周 项目四:数组的排序(1.2字符排序)
- 第十三周项目四——数组的排序(2)
- 第十三周项目四——数组的排序(1)
- 第十三周项目四:数组的排序(3)
- 第十三周项目四——数组的排序(3)
- 第十三周 项目四:数组的排序(1.4选择排序)
- 第十三周项目四 数组的排序(冒泡法按降序排序)
- 第十三周项目四——数组的排序(2)
- 第十三周项目四 数组的排序(选择排序按降序排列)
- 第十三周项目四数组的排序(3)
- 第十三周项目 4 数组的排序(字符数组的排序)
- 第十三周项目4-数组的排序(2 字符数组的排序)
- 第十三周 项目四--数组的排序(1)对数字排序
- 第十三周项目四——数组的排序(3)
- 第十三周项目4-数组的排序:冒泡排序
- 第十三周项目 4 数组的排序(选择排序)
- 第十三周项目四 给数组里的数排序
- 第十三周项目4-数组的排序(1 冒泡排倒序)
- 第十三周项目四(二):字符数组排序
- 第十三周 项目四--数组的排序(3)选择排序