p53_54test.cpp
上传用户:chaiyuqiu
上传日期:2022-08-03
资源大小:27k
文件大小:1k
源码类别:

数据结构

开发平台:

C/C++

  1. //Test is T55_59.cpp
  2. #include <iostream.h>
  3. const int MaxTerms = 100;
  4. template <class Type> class SparseMatrix; //稀疏矩阵的类声明
  5. template <class Type> class Trituple { //三元组类Trituple
  6. friend class SparseMatrix<Type> ;
  7. friend istream & operator >> ( istream & , SparseMatrix<Type> & );
  8. friend ostream & operator << ( ostream & , SparseMatrix<Type> & );
  9. private:
  10.    int row, col; //非零元素的行号、列号
  11.    Type value; //非零元素的值
  12. };
  13. template <class Type> class SparseMatrix {
  14. //对象: 是一个三元组<row, column, value>的集合。其中, row和column是整数, 记忆矩阵
  15. //元素所在的行号和列号,而value是矩阵元素的值。
  16. friend istream & operator >> ( istream & , SparseMatrix<Type> & );
  17. friend ostream & operator << ( ostream & , SparseMatrix<Type> & );
  18. public:
  19.    SparseMatrix ();
  20.    SparseMatrix ( int MaxRow, int MaxCol ): Rows( MaxRow ), Cols( MaxCol ){};    //构造函数
  21. //建立一个MaxRow行, Maxcol列的稀疏矩阵。
  22.    SparseMatrix<Type> Transpose ( );
  23. //对*t