Sort M elements of given circular array starting from index K | Function to print the circular array ; Print the array ; Function to sort m elements of diven circular array starting from index k ; Traverse M elements ; Iterate from index k to k + m - 1 ; Check if the next element in the circular array is less than the current element ; Swap current element with the next element ; Print the circular array ; Driver Code ; Function Call
def printCircularArray ( arr , n ) : NEW_LINE INDENT for i in range ( n ) : NEW_LINE INDENT print ( arr [ i ] , end = " ▁ " ) NEW_LINE DEDENT DEDENT def sortCircularArray ( arr , n , k , m ) : NEW_LINE INDENT for i in range ( m ) : NEW_LINE INDENT for j in range ( k , k + m - 1 ) : NEW_LINE INDENT if ( arr [ j % n ] > arr [ ( j + 1 ) % n ] ) : NEW_LINE INDENT arr [ j % n ] , arr [ ( j + 1 ) % n ] = ( arr [ ( j + 1 ) % n ] , arr [ j % n ] ) NEW_LINE DEDENT DEDENT DEDENT printCircularArray ( arr , n ) NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ 4 , 1 , 6 , 5 , 3 ] NEW_LINE K = 2 NEW_LINE M = 3 NEW_LINE N = len ( arr ) NEW_LINE sortCircularArray ( arr , N , K , M ) NEW_LINE DEDENT