Sort even and odd placed elements in increasing order | C # implementation of the approach ; function to print the odd and even indexed digits ; lists to store the odd and even positioned digits ; traverse through all the indexes in the integer ; if the digit is in odd_index position append it to odd_position list ; else append it to the even_position list ; print the elements in the list in sorted order ; Driver code
using System ; using System . Collections . Generic ; class GFG { static void odd_even ( int [ ] arr , int n ) { List < int > odd_indexes = new List < int > ( ) ; List < int > even_indexes = new List < int > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( i % 2 == 0 ) odd_indexes . Add ( arr [ i ] ) ; else even_indexes . Add ( arr [ i ] ) ; } odd_indexes . Sort ( ) ; even_indexes . Sort ( ) ; for ( int i = 0 ; i < odd_indexes . Count ; i ++ ) Console . Write ( odd_indexes [ i ] + " ▁ " ) ; for ( int i = 0 ; i < even_indexes . Count ; i ++ ) Console . Write ( even_indexes [ i ] + " ▁ " ) ; } public static void Main ( String [ ] args ) { int [ ] arr = { 3 , 2 , 7 , 6 , 8 } ; int n = arr . Length ; odd_even ( arr , n ) ; } }