阅读背景:

字符数组排序

来源:互联网 
#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;
}#include <iostream>
using namespace std;
void b



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: