c ++ n full array of Recursive

We learned a recursive small example today: seeking full array of n

#include <. bits / STDC ++ H>
 the using  namespace STD;
 // ! full array of n - n sets of data 
/ * 
    Each full array has n numbers, it will seek a full permutation of n number of decomposition: 
    1 - seeking full array of n-1 
    2- seeking full permutation n-2 of the 
    full array of n-3 3- request     
            . 
            . 
            . 
    N- seeking full array 1    
* / 
    int n-;
     int Data [ 100 ];
 // void the swap (int & X, Y int &) { // swap values of the number of 
 //     int X = TEMP;
 //     X = Y;
 //     Y = TEMP;
 // } 
void the swap ( int * X, intY *) { // parameter is two pointers 
    int TEMP * = X; 
    X = Y;
     * Y = TEMP; 
} 
void Solve ( int T) {
     int I;
     IF (T == n-) 
    { 
        for (I = . 1 ; I <= n-; I ++ ) 
            COUT << Data [I] << "  " ; 
        COUT << endl; 
         return ; 
    } 
// before t next determines the determined number of the latter number for (I = t; I <= n-; I ++ ) { // value of two numbers each exchange the swap (Data [I], Data [T]); // enter recursive -------> each entry solve () Check the number of starts on the t + 1 // if t == n then groups are arranged on the output data Solve (T + . 1 ); // restore the original state of the array is the swap (data [I], data [T]); } } int main () { // initialize an array memset (data, 0 , the sizeof (Data)); COUT << " INPUT n-: " ; CIN >> n-; // array into a value for ( int I = . 1 ; I <= n-; I ++ ) Data [I]=i; solve(1); }

Back to continue their efforts, I wish, I wish you persevered on the path algorithm.

Guess you like

Origin www.cnblogs.com/Tisou1/p/12173565.html