Rearrange array such that difference of adjacent elements is in descending order | Function to print array in given order ; Sort the array ; Check elements till the middle index ; Check if length is odd print the middle index at last ; Print the remaining elements in the described order ; Driver code ; Array declaration ; Size of array
def printArray ( a , n ) : NEW_LINE INDENT a . sort ( ) ; NEW_LINE i = 0 ; NEW_LINE j = n - 1 ; NEW_LINE while ( i <= j ) : NEW_LINE INDENT if ( i == j ) : NEW_LINE INDENT print ( a [ i ] , end = " ▁ " ) ; NEW_LINE DEDENT else : NEW_LINE INDENT print ( a [ j ] , end = " ▁ " ) ; NEW_LINE print ( a [ i ] , end = " ▁ " ) ; NEW_LINE DEDENT i = i + 1 ; NEW_LINE j = j - 1 ; NEW_LINE DEDENT print ( ) ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr1 = [ 1 , 2 , 3 , 4 , 5 , 6 ] ; NEW_LINE n1 = len ( arr1 ) ; NEW_LINE printArray ( arr1 , n1 ) ; NEW_LINE DEDENT