Sort the tup vector sort ( tup . begin ( ) , tup . end ( ) ) ;
tup . sort ( function ( a , b ) { if ( a [ 0 ] == b [ 0 ] ) { if ( a [ 1 ] == b [ 1 ] ) { return a [ 2 ] - b [ 2 ] ; } else { return a [ 1 ] - b [ 1 ] ; } } return a [ 0 ] - b [ 0 ] ; } ) ; curr = tup [ 0 ] [ 1 ] ; currPos = tup [ 0 ] [ 2 ] ;