📄 sparsematrix.cpp
字号:
#include<iostream.h>
#include"SparseMatrix.h"
template<class Type> SparseMatrix<Type>::SparseMatrix()
{
Rows=0;
Cols=0;
Terms=0;
smArray=NULL;
}
template<class Type> void SparseMatrix<Type>::Transpose()
{
}
template<class Type> void SparseMatrix<Type>::FastTranspose()
{
}
template<class Type> SparseMatrix<Type> SparseMatrix<Type>::Multiply(SparseMatrix<Type> c)
{
return *this;
}
template<class Type> istream&operator>>(istream &input,SparseMatrix<Type> a)
{
Type va;
Trituple<Type> *b=a.smArray;
cout<<"please enter SparseMatrix's Rows , Cols and Terms."<<endl;
cout<<"Rows:";
input>>a.Rows;
cout<<" Cols:";
input>>a.Cols;
cout<<" Terms:";
input>>a.Terms;
cout<<endl;
for(int i=0;i<a.Rows;i++)
{
for(int j=0;j<a.Cols;j++)
{
input>>va;
if(!va)
{
b->row=i;
b->col=j;
b++;
a.Terms++;
}
}
}
return input;
}
template<class Type> ostream&operator<<(ostream &output,SparseMatrix<Type> a)
{
int b=a.Terms;
int i=0;
int j=0;
int m=0;
int n=0;
Trituple<Type> *p=a.smArray;
while(b)
{
i=p->col;
j=p->row;
while(m!=i||n!=j)
{
output<<0<<" "<<;
m++;
if(m==a.Cols)
{
m=0;
n++;
output<<endl;
}
}
output<<p->value<<" ";
m++;
if(m==a.Cols)
{
m=0;
n++;
output<<endl;
}
b--;
p++;
}
while(!(m==a.Cols&&n==a.Rows))
{
output<<0<<" "<<;
m++;
if(m==a.Cols)
{
m=0;
n++;
output<<endl;
}
}
return output;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -