首页 > 其他 > 详细

显示字符串的全排列

时间:2014-10-28 15:03:30      阅读:127      评论:0      收藏:0      [点我收藏+]

显示字符串的全排列:

 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     }

 

显示字符串的全排列

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!