Permutation...


helo..wan ask something. i permutate this 2314 as below for all combination.
let say after i permutate, i want to compare a string(exmple string name("3214") with all the combination comes from permutation just now. And finally display the one from the combination that same with 3124. How to do this?? help plz..



// Assume this is what you want to permute:
string numbers( "2314" );
int i=0;

// next_permutation requires the first permutation to be in sorted order
sort( numbers.begin(), numbers.end() );

// The sorted sequence is the first permutation
cout << numbers << endl;

// Loop through all permutations...


{while( next_permutation( numbers.begin(), numbers.end() ) )}
Last edited on
next_permutation modifies numbers.

1
2
3
while( next_permutation( numbers.begin(), numbers.end() ) 
    if( numbers == "3214" )
        cout << "A match." << endl;

Topic archived. No new replies allowed.