Data Str & Algorithm HW Solutions 80

Data Str & Algorithm HW Solutions 80 - for(each...

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

View Full Document Right Arrow Icon
80 Chap. 12 Lists and Arrays Revisited // For each element, switch row and column pointers, // and its row/column indices. for (each row) for (each element in the row) { swap(nextrow, nextcol); swap(prevrow, prevcol); swap(row, col); } swap(row, col); // Swap row and column list headers } 12.11 Here is pseudocode to add two sparse matrices. // The current object will be the result of adding // its two inputs. SMhead *temp1 = In1->row; SMhead *temp2 = In2->row; while ((temp1 != NULL) || (temp2 != NULL)) if ((temp2 == NULL) || (temp1->index < temp2->index)) { // Insert row from first matrix
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: for (each elem in temp1’s row) this.insert(elem->value, elem->row, elem->col); } else if ((temp1==NULL) || (temp2->index < temp1->index)) { // Insert row from second matrix for (each elem in temp2’s row) this.insert(elem->value, elem->row, elem->col); } else { // Both matrices have this row SMElem* curr1 = temp1->first; SMElem* curr2 = temp2->first; if ((curr2 == NULL) || (curr1->col < curr2->col)) { // Insert element from first matrix this.insert(curr1->value, curr1->row, curr1->col); curr1 = curr1->nextcol; } else if ((curr1 == NULL) || (curr2->col < curr1->col)) {...
View Full Document

This note was uploaded on 12/27/2011 for the course MAP 2302 taught by Professor Bell,d during the Fall '08 term at UNF.

Ask a homework question - tutors are online