how do you sort an array of strings into alphabetical order using bubble sort.
do you use strcpy() to swop the strings around.
how do you sort an array of strings into alphabetical order using bubble sort.
do you use strcpy() to swop the strings around.
char *str[5]={"string","sorting","with","bubble","sort"};
char *tmp;
for(i=1;i<5;++i)
for(j=4;j>=i;--j) if (strcmp(str[j-1],str[j])>0){
tmp=str[j-1];
str[j-1]=str[j];
str[j]=tmp;
}
after sorting:
str[1] --> bubble
str[2] --> sort
str[3] --> sorting
str[4] --> string
str[5] --> with