⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sparsematrix.h

📁 清华大学计算机系数据结构课程教材《数据结构 用面向对象方法和C++描述》(殷人昆主编)的类库(书中程序的源代码)
💻 H
字号:
//稀疏矩阵类
#ifndef SPARSEMATRIX
#define SPARSEMATRIX
#define maxTerms 30
const int drows = 6,  dcols = 7, dterms = 9;
template<class E>
struct Triple {               //三元组
     int row, col;	       //非零元素行号/列号
     E value;                   //非零元素的值
     void operator = (Triple<E>& R)      //赋值
        { row = R.row;  col = R.col;  value = R.value; }
	 Triple(int row = drows, int col = dcols, int value = 10000): row(row), col(col), value(value){}
};			

template <class E>
class SparseMatrix {
public: 
     SparseMatrix (int Rw = drows, int Cl = dcols,
          int Tm = dterms, Triple<E>* sma = NULL);                   //构造函数
     void Transpose(SparseMatrix<E>& b);    //转置
     void FastTranspos(SparseMatrix<E>& b); //快速转置
     SparseMatrix<E> Add(SparseMatrix<E>& b);        //a = a+b
     SparseMatrix<E> Multiply(SparseMatrix<E>& b);         //a = a*b
	 void show(void (*visit)(Triple<E> sm)) {
		 cout << "col          row           value" << endl;
		 for(int i = 0; i < Terms; ++i)
			 visit(smArray[i]);
	 }
private:
     int Rows, Cols, Terms;        //行/列/非零元素数
     Triple<E> *smArray;          //三元组表
};        
#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -