我是靠谱客的博主 糊涂小海豚,这篇文章主要介绍全排列应用:输出子集,现在分享给大家,希望可以做个参考。

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
public class Main { public static void main(String[] args) { String s = "12345"; char[] c = s.toCharArray(); for (int i = 0; i < c.length; i++) { char [] cc = new char[i+1]; for (int j = 0; j < cc.length; j++) { cc[j] = c[j]; } permutation(0,i,cc); } } private static void permutation(int left, int right, char[] c) { if(left == right){ System.out.println(new String(c)); } for (int i = left; i <= right ; i++) { swap(c,i,left); permutation(left+1,right,c); swap(c,i,left); } } private static void swap(char[] c, int left, int right) { char temp = c[left]; c[left] = c[right]; c[right] = temp; } }

最后

以上就是糊涂小海豚最近收集整理的关于全排列应用:输出子集的全部内容,更多相关全排列应用内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(60)

评论列表共有 0 条评论

立即
投稿
返回
顶部