#include #include using namespace std; template //三元组 struct Trituple { int row; int col; T val; }; //稀疏矩阵声明 template class SparseMatrix { public: SparseMatrix(int maxt=100); ~SparseMatrix(); bool TransposeTo(SparseMatrix &); bool AddTo(const SparseMatrix&); bool TransposeTo_Faster(SparseMatrix&); void Input(); void Output(); private: Trituple* data; int rows,cols,terms; int maxterms; }; template SparseMatrix::SparseMatrix(int maxt) { maxterms=maxt; data=new Trituple[maxterms]; terms=rows=cols=0; } template SparseMatrix::~SparseMatrix() { if (data
=NULL) { delete[] data; } } //普通转置 template bool SparseMatrix::TransposeTo(SparseMatrix &B) { if (terms>B
maxterms) { return false; } B
rows=cols; B
cols=rows; B
terms=terms; if (terms>0) { int p=0; for (int j=1;j0) { int *num,*cpot; num=new int[