we add the condition i <= sortedIndex because we don 't want to traverse   on the sorted part of the queue,   which is the right part.
if ( curr <= min_val and i <= sortedIndex ) : NEW_LINE INDENT min_index = i NEW_LINE min_val = curr NEW_LINE DEDENT