permutation of a string

write a recursive solution to print all the permutations of a string. It is assumed that there are no duplicates in the string. 

Comments

  1. void permutate( char[] str, int index )
    {
    int i = 0;
    if( index == strlen(str) )
    { printf(str);
    return;
    }
    for( i = index; i < strlen(str); i++ )
    {
    swap( str[index], str[i] );
    permutate( str, index + 1 );
    swap( str[index], str[i] );
    }
    }

    call initially permutate( "abcdefgh", 0 );

    ReplyDelete

Post a Comment

Popular posts from this blog