Count is used to diffentiate each level of the tree
int count = 1 ; int min_v = Integer . MAX_VALUE ; while ( ! qt . isEmpty ( ) ) { Node temp = qt . peek ( ) ; min_v = Math . min ( min_v , temp . key ) ; qt . remove ( ) ; if ( temp . left != null ) { qt . add ( temp . left ) ; } if ( temp . right != null ) { qt . add ( temp . right ) ; } count -- ; if ( count == 0 ) { levelMin . add ( min_v ) ; min_v = Integer . MAX_VALUE ; count = qt . size ( ) ; } } }