#include
#include
void Sort(char s[][51],int n) {
char t[51];
int i,j,k;
for(i = 0; i < n - 1; ++i) {
k = i;
for(j = i + 1; j < n; ++j) {
if(strcmp(s[k],s[j]) < 0)
k = j;
}
if(k != i) {
strcpy(t,s[i]);
strcpy(s[i],s[k]);
strcpy(s[k],t);
}
}
}
int main() {
char s[][51] = {"continue","break","for","while","struct","swicth","edit","copy","past","please"};
int i,n = 10;
printf("排序前:\n");
for(i = 0; i < n; ++i)
printf("%s\n",s[i]);
Sort(s,10);
printf("\n排序后:\n");
for(i = 0; i < n; ++i)
printf("%s\n",s[i]);
printf("\n");
return 0;
}
#include
void sort(char s[])
{int n,i,j,k;
char c;
for(n=0;s[n];n++);
for(i=0;i {k=i; for(j=i+1;j if(s[j]>s[k])k=j; c=s[i];s[i]=s[k];s[k]=c; } } int main() {char s[200]; int n; scanf("%s",s); sort(s); puts(s); return 0; }
#include
void xuanze(char a[],int n)//选择排序
{
int i,j,k;
char tmp;
for(i=0;i{
k=i;
for(j=i+1;j{
if(a[j]>a[k])
k=j;
}
if(k!=i){
tmp=a[i];
a[i]=a[k];
a[k]=tmp;
}
}
}
int main()
{
int i,n=10;
char a[10]={'a','b','c','d','e','f','g','h','i','j'};
xuanze(a,n);
for(i=0;i<10;i++)
{
printf("%c ",a[i]);
}
}
用选择排序,每次把ASCII码最大的字符放到字符数组的前面
不会吧,有源码么?