N
Newbie
#include <stdio.h>
#include <string.h>
void Permute(char *Perm,
size_t n,
size_t unchanged)
{
size_t outer = 0;
size_t inner = 0;
int temp = 0;
int flag = 0 ;
if(unchanged < n)
{
for(outer = unchanged; outer < n; outer++)
{
/*Rotate the array to the right*/
do {
temp = Perm[outer];
for(inner = outer; inner > unchanged; inner--){
Perm[inner] = Perm[inner - 1];
}
Perm[unchanged] = temp;
/*Done Rotation*/
}while( temp == Perm[unchanged]); /*I need to change outer here*/
/*
All i want here is to continue with rotation above if the first element
of right array is same as that before the rotation takes place.
I know this is really silly but i just cannot figure it out!
Please Help!!!
*/
Permute(Perm,
n,
unchanged + 1);
/*Bring array back into the right order so that the next
recursion level up from here works properly.
*/
for(inner = unchanged; inner < outer; inner++){
Perm[inner] = Perm[inner + 1];
}
Perm[outer] = temp;
}
}
else
{
printf("%s\n", Perm);
}
}
#include <string.h>
void Permute(char *Perm,
size_t n,
size_t unchanged)
{
size_t outer = 0;
size_t inner = 0;
int temp = 0;
int flag = 0 ;
if(unchanged < n)
{
for(outer = unchanged; outer < n; outer++)
{
/*Rotate the array to the right*/
do {
temp = Perm[outer];
for(inner = outer; inner > unchanged; inner--){
Perm[inner] = Perm[inner - 1];
}
Perm[unchanged] = temp;
/*Done Rotation*/
}while( temp == Perm[unchanged]); /*I need to change outer here*/
/*
All i want here is to continue with rotation above if the first element
of right array is same as that before the rotation takes place.
I know this is really silly but i just cannot figure it out!
Please Help!!!
*/
Permute(Perm,
n,
unchanged + 1);
/*Bring array back into the right order so that the next
recursion level up from here works properly.
*/
for(inner = unchanged; inner < outer; inner++){
Perm[inner] = Perm[inner + 1];
}
Perm[outer] = temp;
}
}
else
{
printf("%s\n", Perm);
}
}