Arrange the array such that upon performing given operations an increasing order is obtained | Java program to find the desired output after performing given operations ; 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 ; Driver code ; Given Array
import java . util . Arrays ; class Main { public static void Desired_Array ( int v [ ] ) { int n = v . length ; Arrays . sort ( v ) ; int i = n - 1 ; while ( i > 0 ) { int p = v [ n - 1 ] ; for ( int j = n - 1 ; j >= i ; j -- ) { v [ j ] = v [ j - 1 ] ; } v [ i ] = p ; i -- ; } for ( int x = 0 ; x < v . length ; x ++ ) { System . out . print ( v [ x ] + " ▁ " ) ; } System . out . println ( ) ; } public static void main ( String [ ] args ) { int v [ ] = { 1 , 2 , 3 , 4 , 5 } ; Desired_Array ( v ) ; int v1 [ ] = { 1 , 12 , 2 , 10 , 4 , 16 , 6 } ; Desired_Array ( v1 ) ; } }