字符串全排列

引用剑指offer

 1 //字符串全排列,begin始终指向当前要置换的字符串
 2 void permutation(char* str,char* begin){
 3     if(!str || !begin)
 4         return;
 5     if(*begin=='\0'){
 6         cout<<str<<" ";
 7         return;
 8     }
 9     else{
10         for(char* p=begin;*p!='\0';p++){
11             //交换*p和*begin
12             swap(*p,*begin);
13             permutation(str,begin+1);
14             //重新换回*P和*begin
15             swap(*p,*begin);
16         }
17     }
18 }

 

posted @ 2014-09-20 10:50  liuzhiminxd  阅读(116)  评论(0编辑  收藏  举报