集合的全排列

来源:互联网 发布:美国标志软件 编辑:程序博客网 时间:2024/05/16 09:24

举例,例如存在集合{1,2,3,4,5},列举所有的子集合。

代码如下:

public static void main(String[] args) {int[] a = { 1, 3, 4, 5 };show_jihe(a);}public static void show_jihe(int[] a) {if (null == a)return;int all_jihe = (1 << a.length) - 1;int m = 0;for (int i = 0; i <= all_jihe; i++) {for (int j = 0; j < a.length; j++) {if ((i & (1 << j)) > 0) {System.out.print(a[j]);}}System.out.print("***************" + (m++) + "\n");}}

0 0
原创粉丝点击