Arrange the array such that upon performing given operations an increasing order is obtained | Function to arrange array in such a way that after performing given operation We get increasing sorted array ; Size of given array ; Sort the given array ; Start erasing last element and place it at ith index ; While we reach at starting ; Store last element ; Shift all elements by 1 position in right ; insert last element at ith position ; print desired Array ; Given Array
def Desired_Array ( v ) : NEW_LINE INDENT n = len ( v ) NEW_LINE v . sort ( ) NEW_LINE i = n - 1 NEW_LINE while ( i > 0 ) : NEW_LINE INDENT p = v [ n - 1 ] NEW_LINE for j in range ( n - 1 , i - 1 , - 1 ) : NEW_LINE INDENT v [ j ] = v [ j - 1 ] NEW_LINE DEDENT v [ i ] = p NEW_LINE i -= 1 NEW_LINE DEDENT for x in v : NEW_LINE INDENT print ( x , end = " ▁ " ) NEW_LINE DEDENT print ( ) NEW_LINE DEDENT v = [ 1 , 2 , 3 , 4 , 5 ] NEW_LINE Desired_Array ( v ) NEW_LINE v1 = [ 1 , 12 , 2 , 10 , 4 , 16 , 6 ] NEW_LINE Desired_Array ( v1 ) NEW_LINE