Print all permutations of a number N greater than itself | Function to print all the permutation which are greater than N itself ; Iterate and count the number of digits in N ; vector to print the permutations of N ; Store digits of N in the vector num ; Iterate over every permutation of N which is greater than N ; Print the current permutation of N ; Function to print all the permutation which are greater than N itself ; Driver code
function printPermutation ( N ) { let temp = N , count = 0 ; while ( temp > 0 ) { count ++ ; temp = parseInt ( temp / 10 , 10 ) ; } let num = new Array ( count ) ; num . fill ( 0 ) ; while ( N > 0 ) { num [ count -- - 1 ] = N % 10 ; N = parseInt ( N / 10 , 10 ) ; } while ( next_permutation ( num ) ) { for ( let i = 0 ; i < num . length ; i ++ ) document . write ( num [ i ] ) ; document . write ( " " ) ; } } function next_permutation ( p ) { for ( let a = p . length - 2 ; a >= 0 ; -- a ) if ( p [ a ] < p [ a + 1 ] ) for ( let b = p . length - 1 ; ; -- b ) if ( p [ b ] > p [ a ] ) { let t = p [ a ] ; p [ a ] = p [ b ] ; p [ b ] = t ; for ( ++ a , b = p . length - 1 ; a < b ; ++ a , -- b ) { t = p [ a ] ; p [ a ] = p [ b ] ; p [ b ] = t ; } return true ; } return false ; } let N = 324 ; printPermutation ( N ) ;