can someone modify this code to do general permutations? what I mean by general permutation is that I should be able to do 5p0 or 5p5 or 5p3...the source codes google helped me to find where all doing "all permutations"...
this is a code to do general combinations using backtracking, hopefully someone can modify it to do general permutations
Code:
void combinationUtil(int arr[], int store[], int start, int end, int stInd, int r)
{ // Current combination is ready to be printed, print it
if (stInd == r)
{
for (int j=0; j<r; j++)
{
printf("%d ", store[j]);
}
printf(" \n");
}
// replace index with all possible elements. The condition
// "end-i+1 >= r-index" makes sure that including one element
// at index will make a combination with remaining elements
// at remaining positions
else
{
for (int str=start; str <= end && end-str+1 >= r-stInd; str++)
{
store[stInd] = arr[str];
combinationUtil(arr, store, str+1, end, stInd+1, r);
}
}
}