[algogeeks] Re: Permutation of a string

2011-04-12 Thread baghel
@subhransu u sure that this code will return the desired output? chk
again dude. he is just considering ordered permutation not the random
permutation.
@sravanreddy yeah i tried for looking implementation of
next_permutation but seems like recursive approach is the best one as
far as producing code in front of interviewer is concern :P

On Apr 12, 5:20 pm, sravanreddy001 sravanreddy...@gmail.com wrote:
 I don't there is any algorithm for this..

 The recursive seems to the best approach for this.
 does anyone know if there is any better approach available?

 On Apr 12, 4:45 pm, Subhransu subhransu.panigr...@gmail.com wrote:







  @baghel: The method returns the desire output.

  But looking for some algo which can do the same.

  *Subhransu Panigrahi
  *
  *Mobile:* *+91-9840931538*
   *Email:* subhransu.panigr...@gmail.com

  On Tue, Apr 12, 2011 at 12:08 AM, baghel anant.bag...@gmail.com wrote:
   This solution is incorrect.you are only considering ordered
   permutations of all the rotations of the list ignoring random
   permutations.
   for eg in abcd you are missing random permutation like acbd.
   here we need implementation of next_permutation() function of c++.
   this http://wordaligned.org/articles/next-permutation might be
   helpful.
   Happy coding

   On Apr 9, 12:13 am, Manish Pathak pathak@gmail.com wrote:
 #include stdio.h
#include string.h
#include stdlib.h
int fact(int n);
void main()
{
char a[20],st_char;
static int i,j,k,n,ctr,main_ctr;
printf(Enter the string : );
//gets(a);
scanf(%s,a);

n=strlen(a);

if(n=1)
{
printf(please enter a valid string );
exit(0);

}

//label :
while(main_ctrn)      //loop till length
{
for(i=0;i=n-2;++i)    //loop to print first character of string ex
   abc,acb
{
ctr=0;
printf(\n);
printf(%c,a[0]);
    for(j=i+1;j=n-1;j++)    //take
    {
        printf(%c,a[j]);
        ctr++;
    }

    if(ctr!=n-1)
    {
        for(k=1;k=i;k++)//  print characters that left in above loop ex
from above i=2 print a[0], then j=3 print a[3], means to print a[1] and
   a[2]

        {
        printf(%c,a[k]);
        ctr++;
        }
    }

}

st_char=a[0];        //ex for abc string this change as a[0]=b;
for(i=0;i=n-2;i++)    //a[1]=c;
    a[i]=a[i+1];    //a[2]=a;

a[n-1]=st_char;

main_ctr++;}

printf(\nDesigned by Manish Pathak );

}

   --
   You received this message because you are subscribed to the Google Groups
   Algorithm Geeks group.
   To post to this group, send email to algogeeks@googlegroups.com.
   To unsubscribe from this group, send email to
   algogeeks+unsubscr...@googlegroups.com.
   For more options, visit this group at
  http://groups.google.com/group/algogeeks?hl=en.-Hide quoted text -

  - Show quoted text -

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Permutation of a string

2011-04-11 Thread baghel
This solution is incorrect.you are only considering ordered
permutations of all the rotations of the list ignoring random
permutations.
for eg in abcd you are missing random permutation like acbd.
here we need implementation of next_permutation() function of c++.
this http://wordaligned.org/articles/next-permutation might be
helpful.
Happy coding

On Apr 9, 12:13 am, Manish Pathak pathak@gmail.com wrote:
  #include stdio.h
 #include string.h
 #include stdlib.h
 int fact(int n);
 void main()
 {
 char a[20],st_char;
 static int i,j,k,n,ctr,main_ctr;
 printf(Enter the string : );
 //gets(a);
 scanf(%s,a);

 n=strlen(a);

 if(n=1)
 {
 printf(please enter a valid string );
 exit(0);

 }

 //label :
 while(main_ctrn)      //loop till length
 {
 for(i=0;i=n-2;++i)    //loop to print first character of string ex abc,acb
 {
 ctr=0;
 printf(\n);
 printf(%c,a[0]);
     for(j=i+1;j=n-1;j++)    //take
     {
         printf(%c,a[j]);
         ctr++;
     }

     if(ctr!=n-1)
     {
         for(k=1;k=i;k++)//  print characters that left in above loop ex
 from above i=2 print a[0], then j=3 print a[3], means to print a[1] and a[2]

         {
         printf(%c,a[k]);
         ctr++;
         }
     }

 }

 st_char=a[0];        //ex for abc string this change as a[0]=b;
 for(i=0;i=n-2;i++)    //a[1]=c;
     a[i]=a[i+1];    //a[2]=a;

 a[n-1]=st_char;

 main_ctr++;}

 printf(\nDesigned by Manish Pathak );







 }

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.