print all Permutation of a string

void permutation(char *Pbegin, char *Pend)
{
    if(!Pbegin || !Pend)
    return;
    ///////////////////////
    //if Pbegin equal to Pend
    //this round is finished
    //print 
    if(*Pend)
    {
        printf("%s",Pbegin);
    }
    ///////////////////////
    else
    {
        for(char *c=Pend; *c; c++)
        {
            // swap c and Pend
            swap(c,Pend);
            Pertumation(Pbegin, Pend+1);
            swap(c,Pend);    
        }
    }
}



posted @ 2007-09-21 22:46  HonestMan  阅读(220)  评论(0编辑  收藏  举报