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 indexPre = pre.length;
		int[] used = new int[post.length];
		int usedIndex = 0;
		for (int i = 0; i < post.length; i++) {
			int flag = 1;
			// update used
			for (int j = 0; j < usedIndex; j++) {
				if (post[i] == used[j]) {
					flag = -1;
					break;
				}
			}

			if (flag == 1) {
				used[usedIndex] = post[i];
				usedIndex++;
				
				// update pre
				int[] currentPre = new int[indexPre + 1];
				for (int j = 0; j < indexPre; j++) {
					currentPre[j] = pre[j];
				}
				currentPre[indexPre] = used[usedIndex-1];

				// 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;
	}