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
function Desired_Array ( v ) { let n = v . length ; v . sort ( function ( a , b ) { return a - b } ) ; let i = n - 1 ; while ( i > 0 ) { let p = v [ n - 1 ] ; for ( let j = n - 1 ; j >= i ; j -- ) { v [ j ] = v [ j - 1 ] ; } v [ i ] = p ; i -- ; } for ( let x = 0 ; x < v . length ; x ++ ) { document . write ( v [ x ] + " " ) ; } document . write ( " " ) ; } let v = [ 1 , 2 , 3 , 4 , 5 ] ; Desired_Array ( v ) ; let v1 = [ 1 , 12 , 2 , 10 , 4 , 16 , 6 ] ; Desired_Array ( v1 ) ;