Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef SPARSE_H_
- #define SPARSE_H_
- #include <iostream>
- #include <cmath>
- #include <vector>
- using std::vector;
- typedef double T;
- //template <class T>
- class rowVecItem{
- int col;
- T val;
- };
- //template <class T>
- class rowVec{
- int row;
- vector <rowVecItem> allRowItems;
- };
- //template <class T>
- class sparseMatrix{
- int maxRows;
- int maxCols;
- vector <rowVec> sparseMatVec;
- public:
- sparseMatrix(int rows, int cols);
- sparseMatrix(const sparseMatrix& sm);
- ~sparseMatrix();
- int getRowCount() const;
- int getColCount() const;
- int getNotEmptyCells();
- void iterateNonZeroRowVals();
- T& operator()(int row, int col);
- T& operator=(const T&);
- sparseMatrix& operator+=(const sparseMatrix& sm);
- vector <rowVec>::iterator begin();
- vector <rowVec>::iterator end();
- rowVec& at(int index);
- const rowVec& at(int index) const;
- };
- sparseMatrix operator+(const sparseMatrix& sm1, const sparseMatrix& sm2);
- sparseMatrix operator*(const sparseMatrix& sm1, const sparseMatrix& sm2);
- vector <rowVec>::iterator sparseMatrix::begin(){
- return sparseMatVec.begin();
- }
- vector <rowVec>::iterator sparseMatrix::end(){
- return sparseMatVec.end();
- }
- rowVec& sparseMatrix::at(int index){
- return sparseMatVec.at(index);
- }
- sparseMatrix::sparseMatrix(const sparseMatrix& sm){
- maxRows = sm.getRowCount();
- maxCols = sm.getColCount();
- }
- int sparseMatrix::getRowCount() const{
- return maxRows;
- }
- int sparseMatrix::getColCount() const{
- return maxCols;
- }
- /*
- template <class T>
- class rowVecItem{
- int col;
- T val;
- };
- template <class T>
- class rowVec{
- //typedef ___ iterator; - public/private
- int row;
- vector <rowVecItem<T> > allRowItems[0];
- };
- template <class T>
- class sparseMatrix{
- // iterator - public/private
- vector <rowVec<T> > sparseMatVec[0];
- };
- */
- #endif /* SPARSE_H_ */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement