#include <iostream>
using namespace std;
void bubble_sort(char s[],int n);
void output_array(char s[],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','b','a','j','y','q','e','s','j','c','z','o','e','p','m'};
bubble_sort(a,20);
output_array(a,20);
bubble_sort(b,15);
output_array(b,15);
return 0;
}
void bubble_sort(char s[], int n)
{
int i,j,t;
for(j=0; j<=n-2; j++)
for(i=0; i<=n-j-2; i++)
if (s[i]<s[i+1])
{
t=s[i];
s[i]=s[i+1];
s[i+1]=t;
}
}
void output_array(char s[], int n)
{
int i;
for(i=0; i<=n-1; i++)
cout<<s[i]<<" ";
cout<<endl;
return;
}
字符数组排序
最新推荐文章于 2022-04-20 21:28:42 发布