递归 全排列

来源:互联网 发布:tensorflow官方 编辑:程序博客网 时间:2024/06/05 15:52
void swapChar(char str[], int i, int j){int t = str[j];str[j] = str[i];str[i] = t;}void showString(char str[], int len){if (len == 0){cout << str-4 << endl;return;}for (int i = 0; i < len; i++){swapChar(str, 0, i);showString(str + 1, len - 1);swapChar(str, 0, i);}}int main(){/*int a[] = { 1, 2, 7, 4, 6, 6, 7, 8, 10, 4 };for (int i = 0; i < 10; i++){cout << random_select(a, 0, 9, i+1) << endl;}*/char str[] = "abcd";showString(str, 4);return 0;}

0 0
原创粉丝点击