public void nextPermutation(int[] num) {
		// step 1
		// Find the largest index k such that a[k] < a[k + 1].
		int k = -1;
		for (int i = 0; i < num.length - 1; i++) {
			if (num[i] < num[i + 1])
				k = i;
		}
		// If no such index exists, the permutation is the last permutation.
		if (k == -1) {
			Arrays.sort(num);
			return;
		}
		// step 2
		// Find the largest index l such that a[k] < a[l].
		int l = 0;
		for (int i = 0; i < num.length; i++) {
			if (num[k] < num[i]) {
				l = i;
			}
		}
		// step 3
		// Swap the value of a[k] with that of a[l].
		int temp = num[k];
		num[k] = num[l];
		num[l] = temp;
		// step 4
		// Reverse the sequence from a[k + 1] up to and including the final
		// element a[n].
		int i = k + 1, j = num.length - 1;
		while (i < j) {
			temp = num[i];
			num[i++] = num[j];
			num[j--] = temp;
		}

	}