Title description: this problem is to make you input: {‘ a ‘, ‘b’, ‘c’}, such arrays, and returns the corresponding combination, ‘ABC’ and ‘acb’, ‘America’ and ‘bca’, ‘cab’, ‘the cba.
Analysis: this problem in the book analysis with recursion, relatively simple recursion, logic is much clearer.
#include <stdio.h> #include <stdlib.h> void perhost(char *str,char *beginStr) // { if(*beginStr=='\0') // When beginStr=='\0', print {printf("%s\n", STR); }else {for(char *p=beginStr; *p! = '\ 0'; Char TMP =*p; // Start with beginStr[0] *p=*beginStr; *beginStr=tmp; perhost(str,beginStr+1); Beginstr [0+1] TMP =*p; beginstr[0+ x] TMP =*p; *p=*beginStr; *beginStr=tmp; }}} void host(char * STR) {if(STR ==NULL) // if STR ==NULL,return {return; } perhost(str,str); / / character array pass twice in} int main () {char STR [] = {' b ', 'c', 'd'}; // An array of characters to pass in. host(str); }Copy the code