public void nextPermutation(int[] num) {

        int current = num.length - 1;
        //when find the first descending order element (from end to begin order), reverse these elements
        while (current > 0 && num[current - 1] >= num[current]) {
            current--;
        }
        reverse(num, current, num.length - 1);
        //move current to that special number
        int next = current;
        current--;
        //find the minimum element in the order elements which bigger than the special number, swap them
        while (next < num.length) {
            if (current >= 0 && num[next] > num[current]) {
                swap(num, next, current);
                break;
            }
            next++;
        }
    }