程序员面试100题之二十八,字符串的排列

#include "stdafx.h"



void permutation(char * str, char * begin)

{

	if(!str || !begin)

		return;



	if(*begin == '\0')

		printf("%s\n",str);

	else

	{

		for(char * cur = begin; *cur != '\0'; cur++)

		{

			char temp = *cur;

			*cur = *begin;

			*begin = temp;



			permutation(str, begin+1);



			temp = *cur;

			*cur = *begin;

			*begin = temp;



		}

	}

}



int _tmain(int argc, _TCHAR* argv[])

{

	char str[] = "abc";

	permutation(str,str);

	return 0;

}



你可能感兴趣的:(程序员)