C language: Uses Bubble sorting to sort multiple strings (optimized ).
# 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 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, exchanged (n-1) times {flag = 1; // set the flag bit, optimized bubble for (j = 0; j <size-1-I; j ++) {if (strcmp (str [j], str [j + 1])> 0) // constant string address in space {char * tmp = NULL; // exchange address tmp = str [j]; str [j] = str [j + 1]; str [j + 1] = tmp; flag = 0 ;}} if (flag) // It indicates that it is not in the if, that is, the output order {break ;}} for (I = 0; I <size; I ++) {printf ("% s ", str [I]);} printf ("\ n"); system ("pause"); return 0 ;}