Insert into position vector according to infront value
for ( int i = 0 ; i < vp . size ( ) ; i ++ ) { int height = vp [ i ] . first ; int k = vp [ i ] . second ; pos . insert ( pos . begin ( ) + k , height ) ; } int first = -1 , second = -1 ; for ( int i = 0 ; i < pos . size ( ) ; i ++ ) { if ( pos [ i ] == a ) first = i ; if ( pos [ i ] == b ) second = i ; } return abs ( first - second ) ; }