【发布时间】:2015-03-16 23:36:31
【问题描述】:
我将如何在 SML 中实现这一点?是否可以将内部for循环更改为递归内部函数?
void RecursivePermute(char str[], int k) {
int j;
// Base-case: All fixed, so print str.
if (k == strlen(str))
printf("%s\n", str);
else {
// Try each letter in spot j.
for (j=k; j<strlen(str); j++) {
// Place next letter in spot k.
ExchangeCharacters(str, k, j);
// Print all with spot k fixed.
RecursivePermute(str, k+1);
// Put the old char back.
ExchangeCharacters(str, j, k);
}
}
}
【问题讨论】: