Count is used to diffentiate each level of the tree
int count = 1 ; int min_v = int . MaxValue ; while ( qt . Count != 0 ) { Node temp = qt . Peek ( ) ; min_v = Math . Min ( min_v , temp . key ) ; qt . Dequeue ( ) ; if ( temp . left != null ) { qt . Enqueue ( temp . left ) ; } if ( temp . right != null ) { qt . Enqueue ( temp . right ) ; } count -- ; if ( count == 0 ) { levelMin . Add ( min_v ) ; min_v = int . MaxValue ; count = qt . Count ; } } }