public void nextPermutation(int[] num) {
    	int i,j,k,t;
    	
        for(i = num.length - 2; i>=0; i--){
        	if(num[i]>=num[i+1])continue;
        	else break;
        }
        if(i==-1) {
        	sort(num,0,num.length-1);
        	return;
        }
        k = Integer.MAX_VALUE;
        t = -1;
        for(j = num.length-1; j>i; j--){
        	if(num[j] > num[i] && num[j] < k){
        		t = j;
        		k = num[j];
        	}
        }
        
        int tmp = num[t];
        num[t] = num[i];
        num[i] = tmp;
        sort(num,i+1,num.length-1);
    }