字符串的组合排列

已知字符串里的字符是互不相同的,现在任意组合,比如ab,则输出aa,ab,ba,bb,编程按照字典序输出所有的组合。

#include 
#include 

//非简单全排列
void flexiblePermutation(char* str, char* result, int reach) {
	if (!str) {
		return;
	}
	if (reach == strlen(str)) {
		result[strlen(str)] = '\0';
		puts(result);
	} else {
		int i = 0;
		for (; i < strlen(str); i++) {
			result[reach] = str[i];
			flexiblePermutation(str, result, reach + 1);
		}
	}
}

int main(void) {
	char str[] = "fd";
	char result[strlen(str) + 1];
	flexiblePermutation(str, result, 0);
	return EXIT_SUCCESS;
}


你可能感兴趣的:(算法-字符串)