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.