//打印全排列
//http://bbs.chinaunix.net/viewthread.php?tid=469573
void perm(char *str, int pos, int len) {
char tmp;
int i;
if (pos < len-1) {
// recursion.
for (i = pos; i < len; i++) {
// change and recursion.
tmp = str[pos];
str[pos] = str[i];
str[i] = tmp;
perm(str, pos+1, len);
tmp = str[pos];
str[pos] = str[i];
str[i] = tmp;
}
}
else {
// end recursion.
fputs(str, fp);
fputc('/n', fp);
}
return;
}