?? sparsematrix.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); //構(gòu)造函數(shù)
void Transpose(SparseMatrix<E>& b); //轉(zhuǎn)置
void FastTranspos(SparseMatrix<E>& b); //快速轉(zhuǎn)置
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; //行/列/非零元素數(shù)
Triple<E> *smArray; //三元組表
};
#endif
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -