- has not been realized before, today understand
#include <iostream>#include<iterator>using namespacestd;//The output array is fully arranged//Algorithm Ideas://(1) The full arrangement of n elements = (full permutation of n-1 elements) + (another element as prefix);//(2) Export: If only one element is fully arranged, then the output array is finished;//(3) continue to put each element as the first element, and then the element as a prefix, and the rest of the elements continue to be fully arranged, wait until the exit, export, you need to restore the array;voidPermintList[],intKintm) { if(k = =m) {copy (list, list+ M, ostream_iterator<int> (cout," ")); cout<<Endl; return; } for(inti = k; I < m; i++)//For the first time I changed myself{swap (list[k], list[i]); Perm (list, K+1, M); Swap (List[k], list[i]); }}intMain () {intList[] = {1,2,3 }; Perm (List,0,sizeof(List)/sizeof(int)); return 0;}
The output array is fully arranged