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

显示字符串的全排列

时间:2014-10-28 15:06:41      阅读:216      评论:0      收藏:0      [点我收藏+]

标签:style   blog   io   color   ar   for   sp   div   on   

显示字符串的全排列:

 1 public static void AllSequenceofString(String string){
 2         if(string == null)
 3             return;
 4         char[] chars = string.toCharArray();
 5         Permutation(chars,0);
 6     }
 7     private static void Permutation(char[] chars, int index) {
 8         // TODO Auto-generated method stub
 9         if(index == chars.length){
10             for(int i=0;i<chars.length;i++){
11                 System.out.print(chars[i]);
12             }
13             System.out.println();
14         }
15         else{
16             for(int i = index ; i < chars.length;i++){
17                 char temp = chars[i];
18                 chars[i] = chars[index];
19                 chars[index] = temp;
20                 Permutation(chars,index+1);
21                 temp = chars[index];
22                 chars[index] = chars[i];
23                 chars[i] = temp;
24             }
25         }
26     }

 

显示字符串的全排列

标签:style   blog   io   color   ar   for   sp   div   on   

原文地址:http://www.cnblogs.com/hfczgo/p/4056609.html

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