| 引用: public class Permutation { public static int MAX = 4; public static boolean state[] = new boolean[MAX+1]; public static int item[] = new int[MAX+1]; public static String element[] = {"1", "2", "3", "4"}; public static void main(String[] args) { DoPermutation(1); } public static void DoPermutation(int pos) { if (pos > MAX) { for (int j = 1 ; j <= MAX; j++) System.out.print(element[item[j] - 1]); System.out.println(); return; } for (int i = 1; i <= MAX; i++) { if (!state[i]) { state[i] = true; item[pos] = i; DoPermutation(pos+1); state[i] = false; } } } } |
回复主题 [ 返回JAVA讨论区 ] ![]() |
|
|---|---|
| 主题: | help!! 怎么用java实现全排列? |
| 关于我们 - 联系我们 - 加入我们 - 营销服务 - 友情链接 - 频道合作- PChome Widget Copyright © 1996-2009 PChome.net All rights reserved. 电脑之家 版权所有 |