#define _CRT_SECURE_NO_WARNINGS 1#include<stdio.h> #include <stdlib.h> #include <string.h >int main () { char *str[] = { "Hello", "change", "World", "come ", " on " }; //pointer array, each of which is a character pointer int i = 0; int j = 0; int flag; int size = sizeof (str) / sizeof (str[0 ]); for (i = 0; i < size - 1; i++) // n Strings, swap (n-1) times { flag = 1; //set flag bit, optimize bubble for (j = 0; j <size - 1 - i; j++) { if (strcmp (str[j], str[j + 1]) > 0) //constant string at the address of the space { char *tmp = null; //Exchange Address tmp = str[j]; str[j] = str[j + 1]; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;STR[J&NBSP;+&NBSP;1] = tmp; flag = 0; } } if (flag) //Description does not enter the if internal, that is, the required output order has not been swapped { break; } } for (i = 0; i < size; i++) { printf ("%s ", str[i]); } printf ("\ n"); system ("pause"); return 0;}
650) this.width=650; "title=" string interchange. png "src=" http://s3.51cto.com/wyfs02/M00/75/F3/ Wkiol1zfnejxgrq2aabl-oo3hom938.png "alt=" Wkiol1zfnejxgrq2aabl-oo3hom938.png "/>
C Language: Use bubble sort to sort multiple strings (optimizations).