Swap if previous value is greater
let temp = data [ Math . floor ( j / col ) ] [ j % col ] ; data [ Math . floor ( j / col ) ] [ j % col ] = data [ Math . floor ( ( j + 1 ) / col ) ] [ ( j + 1 ) % col ] ; data [ Math . floor ( ( j + 1 ) / col ) ] [ ( j + 1 ) % col ] = temp ; } } } } function printMat ( mat , row , col ) {