Recursive full arrangement of C Language

Source: Internet
Author: User
C language-full Arrangement

/* Question 6
Write by Arden For TLS
This program guide u to type a n <10 array, and then print out the permutation
*/

# Include <stdio. h>

# Define max 10 // define the maximum array index
Void pmute (INT base [], int pstion, int N)
// Calculate the full arrangement from pstion to N in array base []
{
Int I, temp;
If (pstion = N-1) // The output after completing an arrangement
{
For (I = 0; I <n; I ++)
Printf ("% d", base [I]); // or write to a file, the efficiency will be improved.
Printf ("");

}
Else
{
For (I = pstion; I <n; I ++) // start from position pstion
{
Temp = base [pstion];
Base [pstion] = base [I];
Base [I] = temp; // exchange data to get an arrangement for this location, and then look for the following arrangement
 
Pmute (base, pstion + 1, n); // recursively move the position of pstion to the back
 
Temp = base [pstion]; // Restore for next exchange
Base [pstion] = base [I];
Base [I] = temp;
}
}
}
Void main () // an implementation of pmute
{
Int B [Max];
Int I, N;
Printf ("Type N :");
Scanf ("% d", & N );
Printf ("initalization you base integer array base [% d]:/N", max );
If (n <= 10 ){
For (I = 0; I <n; I ++)
{
Printf ("base [% d]:", I );
Scanf ("% d", & B [I]);
}

Pmute (B, 0, N );
// Printf ("");
}
 
}

My colleague and friend wrote their homework yesterday afternoon. We still need to study the algorithm well... to be improved.

The program does not add the output efficiency is good, after the addition of N> 10 obviously the new rate cannot keep up.

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.