冒泡排序多個字符串

#include<stdio.h>
#include<string.h>

void str_bobble_sort(char *a[],int count)
{
	int i = 0, j =0 ;
	for (i = 0; i < count - 1; i++)
	{
		for (j = 0; j < count - 1 - i; j++)
		{
			if (strcmp(a[j],a[j+1])>0)
			{
				char *tmp = a[j];
				a[j] = a[j + 1];
				a[j + 1] = tmp;
			}

		}
	}
}

int main()
{
	int i = 0;
	char *a[] = { "hhhh","aaaa", "cccc", "bbbb", "dddd","llll" };
	str_bobble_sort(a,sizeof(a)/sizeof(a[0]));
	for (i = 0; i < sizeof(a) / sizeof(a[0]); i++)
	{
		printf("%s\n", a[i]);
	}
	system("pause");
	return 0;
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章