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

全排列

时间:2015-03-16 17:42:16      阅读:95      评论:0      收藏:0      [点我收藏+]

标签:

 1 void swap(char[] a, int i, int j)
 2     {
 3         char tmp = a[i];
 4         a[i] = a[j];
 5         a[j] = tmp;
 6     }
 7     
 8     void Perm(char[] a, int from, int to)
 9     {
10         if(to <=1 )
11             return;
12         if(from == to)
13         {
14             for(int i = 0; i <= to; i++)
15                 System.out.print(a[i]);
16             System.out.println();
17         }
18         else
19         {
20             for(int j = from; j <= to; j++)
21             {
22                 swap(a, j, from);
23                 Perm(a, from+1, to);
24                 swap(a, j, from);
25             }
26         }            
27     }

 

全排列

标签:

原文地址:http://www.cnblogs.com/david-wang/p/4342341.html

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