// ======================< SPARSE.HPP >======================= // * Class MatrixSparse * // * Description: Chapter 13 * // * Scientific C++ Building Numerical Libraries * // * the Object-Oriented Way * // * by G. Buzzi-Ferraris * // * Addison-Wesley (1993) * // =========================================================== #ifndef SPARSE_HPP #define SPARSE_HPP // =========================================================== // ================= class MatrixSparse ================== // =========================================================== struct Element { int column; float value; Element *next; }; class MatrixSparse { private: static const char *const ERROR; int numRows,numColumns; Element **elementRow; float &InsertElement (Element *elem,int row,int column,int first); void Initialize(int rows,int columns); void Copy(const MatrixSparse &rval); public: // =========================================================== // ****************** constructors *********************** // =========================================================== // default constructor MatrixSparse(void); // copy constructor MatrixSparse(const MatrixSparse &rval); // sizing constructor MatrixSparse(int rows,int columns); // =========================================================== // ******************** destructor *********************** // =========================================================== ~MatrixSparse(void); // =========================================================== // ****************** Access functions ******************* // =========================================================== // number of rows int Rows(void) const {return numRows;} // number of columns int Columns(void) const {return numColumns;} // assigns and receives vector values with control float &operator () (int row,int column); // =========================================================== // ****************** assignment operators ****************** // =========================================================== MatrixSparse &operator = (const MatrixSparse &rval); // =========================================================== // ==================== OPERATIONS ======================= // =========================================================== // =========================================================== // *********************** Sum *************************** // =========================================================== friend MatrixSparse operator + (const MatrixSparse &lval,const MatrixSparse &rval); MatrixSparse &operator += (const MatrixSparse &rval); // =========================================================== // ******************** Difference *********************** // =========================================================== friend MatrixSparse operator - (const MatrixSparse &lval,const MatrixSparse &rval); MatrixSparse &operator -= (const MatrixSparse &rval); // =========================================================== // ********************** Product ************************ // =========================================================== friend void Product (const MatrixSparse &lval,const Vector &rval, Vector *result); friend Vector operator * (const MatrixSparse &lval,const Vector &rval); // =========================================================== // =========== Non-modifying functions =================== // =========================================================== // ***********************< Print >*************************** void Print(char *msg=""); // =========================================================== // ============= Modifying Functions ======================= // =========================================================== void DeleteElement(int row,int column); void DeleteRow(int row); void DeleteColumn(int column); void DeleteMatrix(void); void CleanMatrix(void);// eliminates all elements void CleanMatrix(float eps); // eliminates those <= eps // =========================================================== // ========= System solution functions =================== // =========================================================== void SolveRight(Vector *bx); void SolveLeft(Vector *bx); friend void Solve(MatrixSparse *A,Vector *bx); }; #endif SPARSE_HPP