Sort even | C # Program to separately sort even - placed and odd placed numbers and place them together in sorted array . ; create evenArr [ ] and oddArr [ ] ; Put elements in oddArr [ ] and evenArr [ ] as per their position ; sort evenArr [ ] in ascending order sort oddArr [ ] in descending order ; Driver code
using System ; using System . Collections . Generic ; class GFG { static void bitonicGenerator ( int [ ] arr , int n ) { List < int > evenArr = new List < int > ( ) ; List < int > oddArr = new List < int > ( ) ; int i = 0 ; for ( i = 0 ; i < n ; i ++ ) { if ( i % 2 != 1 ) { evenArr . Add ( arr [ i ] ) ; } else { oddArr . Add ( arr [ i ] ) ; } } evenArr . Sort ( ) ; oddArr . Sort ( ) ; oddArr . Reverse ( ) ; i = 0 ; for ( int j = 0 ; j < evenArr . Count ; j ++ ) { arr [ i ++ ] = evenArr [ j ] ; } for ( int j = 0 ; j < oddArr . Count ; j ++ ) { arr [ i ++ ] = oddArr [ j ] ; } } public static void Main ( String [ ] args ) { int [ ] arr = { 1 , 5 , 8 , 9 , 6 , 7 , 3 , 4 , 2 , 0 } ; int n = arr . Length ; bitonicGenerator ( arr , n ) ; for ( int i = 0 ; i < n ; i ++ ) { Console . Write ( arr [ i ] + " ▁ " ) ; } } }