text: Recursive Selection Sort | Recursive C # program to sort an array using selection sort ; Return minimum index ; Find minimum of remaining elements ; Return minimum of current and remaining . ; Recursive selection sort . n is size of a [ ] and index is index of starting element . ; Return when starting and size are same ; calling minimum index function for minimum index ; Swapping when index and minimum index are not same ; swap ; Recursively calling selection sort function ; Driver Code ; Calling function ; printing sorted array
code: using System ; class GFG { static int minIndex ( int [ ] a , int i , int j ) { if ( i == j ) return i ; int k = minIndex ( a , i + 1 , j ) ; return ( a [ i ] < a [ k ] ) ? i : k ; } static void recurSelectionSort ( int [ ] a , int n , int index ) { if ( index == n ) return ; int k = minIndex ( a , index , n - 1 ) ; if ( k != index ) { int temp = a [ k ] ; a [ k ] = a [ index ] ; a [ index ] = temp ; } recurSelectionSort ( a , n , index + 1 ) ; } public static void Main ( String [ ] args ) { int [ ] arr = { 3 , 1 , 5 , 2 , 7 , 0 } ; recurSelectionSort ( arr , arr . Length , 0 ) ; for ( int i = 0 ; i < arr . Length ; i ++ ) Console . Write ( arr [ i ] + " ▁ " ) ; } }