The top of the stack modulo k is greater than ( temp & k ) or if they are equal then compare the values
if ( ( tmpStackMod > tmpMod ) || ( tmpStackMod == tmpMod && tmpStack [ tmpStack . length - 1 ] > tmp ) ) {