Data Str & Algorithm HW Solutions 79

Data Str & Algorithm HW Solutions 79 - if...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
79 tempc->nextrow = temp; } } 12.9 void SparseMatrix remove(int r, int c) { // First, find the row for (SMhead* crow = row; (crow->index <= r) & (crow->next != NULL); crow = crow->next); if (crow->index != r) ERROR; // Not in array // Now, find the column for (SMhead* ccol = c; (ccol->index <= c) & (ccol->next != NULL); ccol = ccol >next); if (ccol->index != c) ERROR; // Not in array // Now, find the element for (SMElem* temp = crow->first; (temp != NULL) & (temp->col != c); temp = temp->nextcol); if (temp->col != c) ERROR; // Not in array // Now, detatch the element if (temp->prevrow == NULL) { ccol->first = temp->nextrow;
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: if (temp-&gt;nextrow != NULL) temp-&gt;nextrow-&gt;prevrow = NULL; } else { temp-&gt;prevrow-&gt;nextrow = temp-&gt;nextrow; if (temp-&gt;nextrow != NULL) temp-&gt;nextrow-&gt;prevrow = temp-&gt;prevrow; } if (temp-&gt;prevcol == NULL) { crow-&gt;first = temp-&gt;nextcol; if (temp-&gt;nextcol != NULL) temp-&gt;nextcol-&gt;prevcol = NULL; } else { temp-&gt;prevcol-&gt;nextcol = temp-&gt;nextcol; if (temp-&gt;nextcol != NULL) temp-&gt;nextcol-&gt;prevcol = temp-&gt;prevcol; } } 12.10 Transposing a sparse matrix is fairly straightforward. Here is pseudocode: void SparseMatrix::transpose() {...
View Full Document

Ask a homework question - tutors are online