text: Difference between Insertion sort and Selection sort | C # program for implementation of selection sort ; Function to implement the selection sort ; One by one move boundary of unsorted subarray ; Find the minimum element in unsorted array ; Swap the found minimum element with the first element ; Function to print an array ; Driver Code ; Function Call ; Print the array
code: using System ; public class GFG { static void selectionSort ( int [ ] arr , int n ) { int i , j , min_idx ; for ( i = 0 ; i < n - 1 ; i ++ ) { min_idx = i ; for ( j = i + 1 ; j < n ; j ++ ) if ( arr [ j ] < arr [ min_idx ] ) min_idx = j ; int temp = arr [ min_idx ] ; arr [ min_idx ] = arr [ i ] ; arr [ i ] = temp ; } } static void printArray ( int [ ] arr , int size ) { int i ; for ( i = 0 ; i < size ; i ++ ) { Console . Write ( arr [ i ] + " ▁ " ) ; } Console . WriteLine ( ) ; } public static void Main ( String [ ] args ) { int [ ] arr = { 64 , 25 , 12 , 22 , 11 } ; int n = arr . Length ; selectionSort ( arr , n ) ; Console . Write ( " Sorted ▁ array : ▁ STRNEWLINE " ) ; printArray ( arr , n ) ; } }