📄 main.cpp
字号:
#include <iostream>
using namespace std;
#include "SparseMatrix.h"
#include "SparseMatrix.cpp"
template<class T>
void visit(Triple<T> tmp){
cout << tmp.row << " " << tmp.col << " " << tmp.value << endl;
}
int main(){
Triple<int> a13(1,3,5);
Triple<int> a32(3,2,4);
Triple<int> a41(4,1,6);
Triple<int>* sma1 = new Triple<int>[3];
sma1[0] = a13;
sma1[1] = a32;
sma1[2] = a41;
Triple<int> b23(2,3,5);
Triple<int> b34(3,4,7);
Triple<int> b41(4,1,2);
Triple<int> b53(5,3,3);
Triple<int>* sma2 = new Triple<int>[4];
sma2[0] = b23;
sma2[1] = b34;
sma2[2] = b41;
sma2[3] = b53;
SparseMatrix<int> M1(5,5,3,sma1);
SparseMatrix<int> M2(5,5,4,sma2);
cout<<"矩阵M1:" <<endl;
cout<<"0 0 5 0 0"<<endl;
cout<<"0 0 0 0 0"<<endl;
cout<<"0 4 0 0 0"<<endl;
cout<<"6 0 0 0 0"<<endl;
cout<<"0 0 0 0 0"<<endl;
cout<<"矩阵M2:"<<endl;
cout<<"0 0 0 0 0"<<endl;
cout<<"0 0 5 0 0"<<endl;
cout<<"0 0 0 7 0"<<endl;
cout<<"2 0 0 0 0"<<endl;
cout<<"0 0 3 0 0"<<endl;
cout<<"利用show函数输出:";
cout << "矩阵M1:" << endl;
M1.show(visit);
cout << "矩阵M2:" << endl;
M2.show(visit);
cout << "----------------------------------------------" << endl;
cout << "M1" << endl;
M1.show(visit);
cout << "M2" << endl;
M2.show(visit);
SparseMatrix<int> M(5,5,3);
cout << "----------------------------------------------" << endl;
cout << "M1+M2=" << endl;
M1.Add(M2).show(visit);
cout << "----------------------------------------------" << endl;
cout << "M1*M2=" << endl;
M1.Multiply(M2).show(visit);
cout << "----------------------------------------------" << endl;
cout << "M1 的转置为:" << endl;
M1.Transpose(M);
M.show(visit);
cout << "----------------------------------------------" << endl;
cout << "M1 的快速转置结果:" << endl;
M1.Transpose(M);
M.show(visit);
cout << "----------------------------------------------" << endl;
cout<<"测试完毕"<<endl;
while(1)//为了在类库说明文档中便于观察,加入这一句
cout<<"";
return 0;
}
/*
测试示例:
矩阵M1:
0 0 5 0 0
0 0 0 0 0
0 4 0 0 0
6 0 0 0 0
0 0 0 0 0
矩阵M2:
0 0 0 0 0
0 0 5 0 0
0 0 0 7 0
2 0 0 0 0
0 0 3 0 0
利用show函数输出:矩阵M1:
col row value
1 3 5
3 2 4
4 1 6
矩阵M2:
col row value
2 3 5
3 4 7
4 1 2
5 3 3
----------------------------------------------
M1
col row value
1 3 5
3 2 4
4 1 6
M2
col row value
2 3 5
3 4 7
4 1 2
5 3 3
----------------------------------------------
M1+M2=
col row value
1 3 5
2 3 5
3 2 4
3 4 7
4 1 8
5 3 3
----------------------------------------------
M1*M2=
success
1 4 35 0
3 3 20 1
ss
col row value
1 4 35
3 3 20
----------------------------------------------
M1 的转置为:
col row value
1 4 6
2 3 4
3 1 5
----------------------------------------------
M1 的快速转置结果:
col row value
1 4 6
2 3 4
3 1 5
----------------------------------------------
测试完毕
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -