public int [ ] next ( ) { boolean hasNewPerm = false ; escape : while ( level >= 0 ) { // boolean foundZero = false; for ( int i = iter [ level ] ; i < data . length ; i = iter [ level ] ) { iter [ level ] ++ ; if ( data [ i ] == - 1 ) { level ++ ; data [ i ] = level - 1 ; if ( level >= data . length ) { // a new permutation has been created return the results. hasNewPerm = true ; System . arraycopy ( data , 0 , ret , 0 , ret . length ) ; level = level - 1 ; data [ i ] = - 1 ; break escape ; } else { valk [ level ] = i ; } } } data [ valk [ level ] ] = - 1 ; iter [ level ] = 0 ; level = level - 1 ; } if ( hasNewPerm ) return ret ; return null ; }
Creates the next permutation in the sequence .