字符串排序C

版权声明:允许转载,请注明文章出处 https://blog.csdn.net/Vickers_xiaowei/article/details/83746198
#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;
}

猜你喜欢

转载自blog.csdn.net/Vickers_xiaowei/article/details/83746198
今日推荐