Selection Sort VS Bubble Sort | JavaScript program for above approach ; Driver Code
function Selection_Sort ( arr , n ) { for ( let i = 0 ; i < n - 1 ; ++ i ) { let min_index = i ; for ( let j = i + 1 ; j < n ; ++ j ) { if ( arr [ j ] < arr [ min_index ] ) min_index = j ; } let temp = arr [ i ] ; arr [ i ] = arr [ min_index ] ; arr [ min_index ] = temp ; } } let n = 5 ; let arr = [ 2 , 0 , 1 , 4 , 3 ] ; Selection_Sort ( arr , n ) ; document . write ( " " ) ; for ( let i = 0 ; i < n ; ++ i ) document . write ( arr [ i ] + " " ) ;