#include <iostream>
using namespace std;
void printPermutation(string &s, int cur) {
if (cur == s.size() - 1) {
cout << s << endl;
}
for (int i = cur; i < s.size(); i++) {
swap(s[cur], s[i]);
printPermutation(s, cur + 1);
swap(s[cur], s[i]);
}
}
int main() {
string s = "1234";
printPermutation(s, 0);
return 0;
}
全排列递归实现
最新推荐文章于 2023-11-28 14:19:47 发布