Sort the matrix column | Function to find the transpose of the matrix mat [ ] ; Stores the transpose of matrix mat [ ] [ ] ; Traverse each row of the matrix ; Traverse each column of the matrix ; Transpose matrix elements ; Function to sort the given matrix in row wise manner ; Traverse the row ; Row - Wise Sorting ; Function to print the matrix in column wise sorted manner ; Function call to find transpose of the the matrix mat [ ] [ ] ; Sorting the matrix row - wise ; Calculate transpose of B [ ] [ ] ; Print the matrix mat [ ] [ ] ; Input ; Function call to print the matrix in column wise sorted manner
function transpose ( mat , row , col ) { let tr = new Array ( col ) ; for ( let i = 0 ; i < col ; i ++ ) { tr [ i ] = new Array ( row ) ; } for ( let i = 0 ; i < row ; i ++ ) { for ( let j = 0 ; j < col ; j ++ ) { tr [ j ] [ i ] = mat [ i ] [ j ] ; } } return tr ; } function RowWiseSort ( B ) { for ( let i = 0 ; i < B . length ; i ++ ) { ( B [ i ] ) . sort ( function ( a , b ) { return a - b ; } ) ; } } function sortCol ( mat , n , M ) { let B = transpose ( mat , N , M ) ; RowWiseSort ( B ) ; mat = transpose ( B , M , N ) ; for ( let i = 0 ; i < N ; i ++ ) { for ( let j = 0 ; j < M ; j ++ ) { document . write ( mat [ i ] [ j ] + " " ) ; } document . write ( " " ) ; } } let mat = [ [ 1 , 6 , 10 ] , [ 8 , 5 , 9 ] , [ 9 , 4 , 15 ] , [ 7 , 3 , 60 ] ] ; let N = mat . length ; let M = mat [ 0 ] . length ; sortCol ( mat , N , M ) ;