现在的位置: 首页 > 综合 > 正文

全排列

2013年08月21日 ⁄ 综合 ⁄ 共 378字 ⁄ 字号 评论关闭
#include<stdio.h>
#include<stdlib.h>

void swap(char* str,int i,int j){
	while(i<j){
		char tmp=str[i];
		str[i]=str[j];
		str[j]=tmp;
		i++,j--;
	}
}
void permutation(char* str,int len){
	if(str==NULL||len<=0) return;
	if(len==1){
		printf("%s\n",str);
		return;
	}
	for(int i=0;i<len;i++){
		swap(str,i,len-1);
		permutation(str,len-1);
		swap(str,i,len-1);
	}
}

int main(){
	char str[]="abcd";
	permutation(str,4);
	system("pause");	
	return 0;
}

抱歉!评论已关闭.