0
我該如何在SML中實現這個功能?是否有可能將內部for循環更改爲遞歸內部函數?在sml中實現next_permutation?
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);
}
}
}