A bit like this
Code:
float SparseMatrixRowSum(SparseMatrix *sp, int rowNumber, int column1, int column2) {
float result = 0.0;
rowHeaderPtr row_ptr;
rowhead col_ptr;
// find the row
// this walks the list of rows, looking for the row we want
// stop when that row is found, or we reach the end of the list
for ( row_ptr = sp ;
row_ptr != NULL && row_ptr->rowNum != rowNumber ;
row_ptr = row_ptr->next );
// did we find the row?
if ( row_ptr != NULL ) {
// sum values on this row of data
for ( col_ptr = row_ptr->rowhead ;
col_ptr != NULL ;
col_ptr = col_ptr->next ) {
if ( col_ptr->colNum >= column1 && col_ptr->colNum <= column2 ) {
// this node is in the range of required colums, so add
result += col_ptr->data;
}
}
}
return result;
}