您的位置:首页 > 其它

第十三周项目四数组的排序(2)

2014-11-23 14:39 274 查看
问题及代码:

/*
* 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>

学习心得:

第一个写出来之后,这个就简单多了,把一些地方稍微改一下就可以了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: