Count is used to diffentiate each level of the tree
int count = 1 ; int min_v = INT_MAX ; while ( ! qt . empty ( ) ) { Node * temp = qt . front ( ) ; min_v = min ( min_v , temp -> key ) ; qt . pop ( ) ; if ( temp -> left ) { qt . push ( temp -> left ) ; } if ( temp -> right ) { qt . push ( temp -> right ) ; } count -- ; if ( count == 0 ) { levelMin . push_back ( min_v ) ; min_v = INT_MAX ; count = qt . size ( ) ; } } }