1. 程式人生 > >字串排序C

字串排序C

#include <stdio.h>  
#include <string.h>  
#include<windows.h>
int my_strcmp(const void*x, const void*y)
{
	return *(int*)x > *(int*)y;
}
void bubble_sort_str(char *str[], int sz)
{
	int i = 0;
	int j = 0;
	for (i = 0; i < sz - 1; i++)
	{
		for (j = 0; j < sz - 1 - i; j++
) { if (my_strcmp(*(str + j), *(str + j + 1))>0) { char *tmp = *(str + j); *(str + j) = *(str + j + 1); *(str + j + 1) = tmp; } } } } int main() { int i = 0; char *str[] = { "cccc", "bbbb", "dddd", "aaaa" }; bubble_sort_str(str, sizeof(str) / sizeof(*str)); for (i = 0; i <
sizeof(str) / sizeof(*str); i++) { printf("%s ", *(str + i)); } printf("\n"); system("pause"); return 0; }