三: 全局数组
全局数组初始化, int 类型数组初始化为 0,boolean 数组初始化为 false。
举例:全排列
import java.util.Hashtable;
public class Quanpailie {
private static int n;
private static int maxn = 11;
static int p[] = new int[maxn]; //初始化 maxn 个0
static boolean hashTable[] = new boolean[maxn]; //初始化 maxn 个 false
public static void generateP(int index) {
if (index == n+1) {
for (int i = 1; i <= n; i++) {
System.out.print(p[i]+" ");
}
System.out.println();
return;
}
for (int x = 1; x <= n; x++) {
if (hashTable[x] == false) {
hashTable[x] = true;
p[index] = x;
generateP(index+1);
hashTable[x] = false;
}
}
}
public static void main(String[] args) {
System.out.println(hashTable.length);
for (int i = 0; i < maxn; i++) {
System.out.println(p[i]);
}
n = 3;
generateP(1);
}
}