Function to find the pivot index
def partition ( arr , l , h ) : NEW_LINE INDENT pivot = arr [ l ] NEW_LINE i = l + 1 NEW_LINE j = h NEW_LINE while ( i <= j ) : NEW_LINE INDENT while ( i <= h and arr [ i ] < pivot ) : NEW_LINE INDENT i += 1 NEW_LINE DEDENT while ( j > l and arr [ j ] > pivot ) : NEW_LINE INDENT j -= 1 NEW_LINE DEDENT if ( i < j ) : NEW_LINE INDENT temp = arr [ i ] NEW_LINE arr [ i ] = arr [ j ] NEW_LINE arr [ j ] = temp NEW_LINE i += 1 NEW_LINE j -= 1 NEW_LINE DEDENT else : NEW_LINE INDENT i += 1 NEW_LINE DEDENT DEDENT arr [ l ] = arr [ j ] NEW_LINE arr [ j ] = pivot NEW_LINE return j NEW_LINE DEDENT