#include <iostream>
using namespace std;
//两个函数bubble_sort和output_array的声明
void bubble_sort(char a[],int n)
{
char mid;
for(int i=0;i<n-1;i++)
for(int j=0;j<n-i-1;j++)
{
if((int)a[j]<(int)a[j+1])
{
mid=a[j];
a[j]=a[j+1];
a[j+1]=mid;
}
}
}
void output_array(char a[],int n)
{
for(int i=0;i<n;i++)
{
cout<<"a["<<i<<"]="<<a[i]<<" ";
if((i+1)%5==0)cout<<endl;
}
}
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] = {'e','e','s','o'};//请自己补足
bubble_sort(a,20); //用冒泡法按降序排序a中元素
output_array(a,20);
cout<<endl;
cout<<endl; //输出排序后的数组
bubble_sort(b,15); //用冒泡法按降序排序b中元素
output_array(b,15); //输出排序后的数组
return 0;
}
//请在下面定义bubble_sort和output_array函数
【项目4拓展1 - 字符数组排序】
最新推荐文章于 2024-01-27 22:50:36 发布