码迷,mamicode.com
首页 > 其他好文 > 详细

字符串的全排列

时间:2017-07-31 20:11:03      阅读:84      评论:0      收藏:0      [点我收藏+]

标签:字符串   i++   out   ring   public   字符   from   eof   rom   

递归,注意还原,注意从当前字符开始,即i=from
public static void permutation(char[] ch, int from, int to){
if(to <= from){
System.out.println(String.valueOf(ch));
} else{
for(int i = from; i <= to; i++){
char temp = ch[from];
ch[from] = ch[i];
ch[i] = temp;
permutation(ch,from+1,to);
temp = ch[from];
ch[from] = ch[i];
ch[i] = temp;
}
}
}

字符串的全排列

标签:字符串   i++   out   ring   public   字符   from   eof   rom   

原文地址:http://www.cnblogs.com/zawjdbb/p/7264681.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!