March 2019
Intermediate to advanced
336 pages
9h 9m
English
The SetValue method of the SparseMatrix class sets the value of the cell with the row and column equal to i and j, respectively, as the parameter value:
//SetValue methodfunc (sparseMatrix *SparseMatrix) SetValue(i int, j int, value float64) { var lol LOL var index int for index, lol = range sparseMatrix.cells { if LessThan(lol, i, j) { continue } if Equal(lol, i, j) { sparseMatrix.cells[index].Value = value return } sparseMatrix.cells = append(sparseMatrix.cells, LOL{}) var k int for k = len(sparseMatrix.cells) - 2; k >= index; k-- { sparseMatrix.cells[k+1] = sparseMatrix.cells[k] } sparseMatrix.cells[index] = LOL{ Row: i, Column: j, Value: value, } return } sparseMatrix.cells = append(sparseMatrix.cells, LOL{ Row: i, ...Read now
Unlock full access