ArrayList<ArrayList<Integer>> permuteUnit(int[] num, int[] pre, int[] post,
			ArrayList<ArrayList<Integer>> permutation) {

		// base case
		if (pre.length == num.length) {
			ArrayList<Integer> unit = new ArrayList<Integer>();
			for (int i = 0; i < pre.length; i++) {
				unit.add(pre[i]);
			}
			permutation.add(unit);
			return permutation;
		}
		int index = pre.length;
		for (int i = 0; i < post.length; i++) {
			// update pre
			int[] currentPre = new int[index + 1];
			for (int j = 0; j < index; j++) {
				currentPre[j] = pre[j];
			}
			currentPre[index] = post[i];

			// update post
			int[] currentPost = new int[post.length - 1];
			int j = 0;
			while (j != i) {
				currentPost[j] = post[j];
				j++;
			}
			while (j < currentPost.length) {
				currentPost[j] = post[j + 1];
				j++;
			}

			permuteUnit(num, currentPre, currentPost, permutation);
		}
		return permutation;
	}