C语言实现一个字符串的所有排列方式

版权声明:转载需转载声明 https://blog.csdn.net/qq_32285693/article/details/89597557

 C语言实现一个字符串的所有排列方式!

#include <stdio.h>
#include <stdlib.h>
void Permutation(char*a, char*current);
int main()
{
	char s[30] = "abc";
	Permutation(s, s);
	system("pause");
	return 0;
}
void Permutation(char*a, char*current)
{
	if (*current == '\0')
		printf("%s\n", a);

	for (char*next = current; *next != '\0'; next++)
	{
		char tem = *current;
		*current = *next;
		*next = tem;

		Permutation(a, current + 1);

		tem = *current;
		*current = *next;
		*next = tem;
	}
}

运行截图

猜你喜欢

转载自blog.csdn.net/qq_32285693/article/details/89597557