Queue elements after sortedIndex are already sorted . This function returns index of minimum element from front to sortedIndex
int minIndex ( queue < int > & q , int sortedIndex ) { int min_index = -1 ; int min_val = INT_MAX ; int n = q . size ( ) ; for ( int i = 0 ; i < n ; i ++ ) { int curr = q . front ( ) ;