#include <stdio.h>
void char_sort(char[],int);
void print_array(char[],int);
int main(int argc, char *argv[])
{
char ch1[10] = {'k','c','d','m','z','h','u','q','o','a'};
printf("the source char array:\n");
print_array(ch1,10);
char_sort(ch1,10);
printf("\nthe sort array is :\n");
print_array(ch1,10);
system("pause");
return 0;
}
void char_sort(char ch[], int n)
{
int i,j;
char temp;
for (i = 0 ; i < n - 1; i++)
{
for (j = 0; j < n - 1 - i ;j++)
{
if (ch[j] > ch[j + 1])
{
temp = ch[j];
ch[j]= ch[j + 1];
ch[j + 1] = temp;
}
}
}
}
void print_array(char ch[], int n)
{
int i;
for (i = 0; i < n ; i++)
{
printf("%c ",ch[i]);
}
}
|