Segregate even and odd numbers | Set 3 | Function to segregate even odd numbers ; Swapping even and odd numbers ; Printing segregated array ; Driver code
function arrayEvenAndOdd ( arr , n ) { let i = - 1 , j = 0 ; let t ; while ( j != n ) { if ( arr [ j ] % 2 == 0 ) { i ++ ; let temp = arr [ i ] ; arr [ i ] = arr [ j ] ; arr [ j ] = temp ; } j ++ ; } for ( let i = 0 ; i < n ; i ++ ) document . write ( arr [ i ] + " " ) ; } let arr = [ 1 , 3 , 2 , 4 , 7 , 6 , 9 , 10 ] ; let n = arr . length ; arrayEvenAndOdd ( arr , n ) ;