Selection Sort VS Bubble Sort |  ; Driver code
class GFG { static void Selection_Sort ( int arr [ ] , int n ) { for ( int i = 0 ; i < n - 1 ; ++ i ) { int min_index = i ; for ( int j = i + 1 ; j < n ; ++ j ) { if ( arr [ j ] < arr [ min_index ] ) min_index = j ; } int temp = arr [ i ] ; arr [ i ] = arr [ min_index ] ; arr [ min_index ] = temp ; } } public static void main ( String [ ] args ) { int n = 5 ; int arr [ ] = { 2 , 0 , 1 , 4 , 3 } ; Selection_Sort ( arr , n ) ; System . out . print ( " The ▁ Sorted ▁ Array ▁ by ▁ using ▁ Selection ▁ Sort ▁ is ▁ : ▁ " ) ; for ( int i = 0 ; i < n ; ++ i ) System . out . print ( arr [ i ] + " ▁ " ) ; } }