13_栈的递归实例4---全排列

#include "linkStack.h"

static int number = 0;

void hanoi( char *s , int a , int b ) {

    if ((0 <= a) && (a <= b)){
        if (a == b) {
            cout << s << endl;
            ++number;
        }
        else {
            for (int i = a; i <= b; ++i) {
                if ( (i>a)&&(s[i] == s[a]) ) 
                        continue;
                char temp = s[a];
                s[a] = s[i];
                s[i] = temp;
                hanoi(s, a + 1, b);
                temp = s[a];
                s[a] = s[i];
                s[i] = temp;
            }
        }
    }
}

int main(int argc, char **argv) {

    char s[] = "abca";
    hanoi( s , 0 , 3);
    cout << number << endl;

    system( "pause" );
    return 0;
}