#include #include #include "sparse.h" #define n 6 void main() { int i; int j; // declare a sparse array SparseArray myArray(n,n,0.0); // set up its tridiagonal as in the assignment for (i=0; i= -1 && i-j <= 1) { myArray.Store(i,j,(i+1)+((double)(j+1)/10)); } } } // print it out in a dense format myArray.WriteDense(cout); cout << endl; // print it out in a sparse format myArray.WriteSparse(cout); cout << endl; // use iteration to negate its main diagonal myArray.SetupIteration(1,2); // iterate R->L, top->bottom myArray.GetCursorPosition(i,j); // get first represented value's position while (i != -1) { // loop until we fall off the array if (i == j) { // if on the main diagonal myArray.Store(i,j,-myArray.Read(i,j)); // negate its value } myArray.Advance(); // advance the cursor myArray.GetCursorPosition(i,j); // get the next rep value's position } // print it out again myArray.WriteDense(cout); cout << endl; // print out its density and number of represented elements cout << "Density is: " << myArray.Density() << endl; cout << "Number of represented elements is: "; cout << myArray.NumRepresented() << endl; }