The bubble sort of the string and the whole type bubble sort and the principle is the same, here does not have the bubble sort to do the detailed introduction, gives the source code directly!
#include <stdio.h> #include <stdlib.h> #define N 10int Main () {char *arr[n] = {"Pas", "pase", "abced", "asdf", " Acdef "," Ertugbs "," Jhgsds "," KSJDJFH "," skjsh "," SMJDJG "};int i = 0;int j = 0;int size = sizeof (arr)/sizeof (arr[0]); for (i = 0; i < size-1; i++) {for (j = 0; J < Size-1-i; J + +) {if (strcmp (arr[j],arr[j+1]) >0) {char *tmp = arr[j];arr[j] = arr[j + 1];arr[j + 1] = tmp;}}} for (i = 0; i < size; i++) {printf ("%s", Arr[i]);} printf ("\ n"); system ("pause"); return 0;}
In the above program I have defined the size of the pointer array, you can use it without definition, the direct initialization is good. Because of my learning experience and other reasons, the program must have a lot of loopholes, welcome to the great God of my code to write criticism!
This article is from the "Sharing Progress" blog, be sure to keep this source http://xmwen1.blog.51cto.com/10730069/1712521
Sort a set of strings using bubble sort