Taking the last label of each level of the tree
if ( count == 1 ) { b = temp . second ; } if ( temp . first . left != null ) { qt . push ( new pair ( temp . first . left , 2 * temp . second ) ) ; } if ( temp . first . right != null ) { qt . push ( new pair ( temp . first . right , 2 * temp . second + 1 ) ) ; } count -- ;