Recursive thinking achieves full Arrangement

Source: Internet
Author: User

[Cpp]
# Include <stdio. h>
 
Int Swap (char * a, char * B)
{
Char c;
C = *;
* A = * B;
* B = c;
}
 
/*
* Recursive thinking achieves full Arrangement
* If abc is fully arranged, we can see that AB is fully arranged + c and ac + B and bc + a combination.
*/
Void Perm (char * list, int k)
{
// Arrange the substrings after k in the list Array
Int I;
If ('\ 0' = list [k]) {// output an arrangement
Printf ("% s \ t", list );
Putchar ('\ n ');
}
Else
{
For (I = k; list [I]! = '\ 0'; I ++ ){
Swap (& list [k], & list [I]);
Perm (list, k + 1); // arrange the right substring in full
 
Swap (& list [k], & list [I]);
}
}
}
 
Int main (int argc, char * argv [])
{
Char string [10] = "123 ";
Perm (string, 0 );
Return 0;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.