稀 疏 矩 阵 的 加 、 减 、 乘 、 求 逆 运 算 #include #include using namespace std; const int MAXSIZE = 100; //定义非零元素的最多个数 const int MAXROW = 10; //定义数组行数的最大值 const int SIZENUM = 10; typedef struct //定义三元组元素 { int r, c; //矩阵的行号和列号 int v; //矩阵元素值 }Triple; typedef struct //定义普通三元组对象 { Triple data[MAXSIZE+1]; int rows, cols, nzeroNums; //行数、列数、非零元素个数 }TSMatrix; typedef struct //定义行逻辑链接的顺序表 { Triple data[MAXSIZE+2]; //非0 元三元组表 int rpos[MAXROW+1]; //各行第一个非零元素的位置表 int rows, cols, nzeroNums; //行数、列数、非零元素个数 }RLSMatrix; //输入三元组矩阵 template bool InputTSMatrix(T &M, int y) { cout > M
rows >> M
cols >> M
nzeroNums; cout > M
data[i]
c >> M
data[i]
v; } return true; } //输出矩阵,按标准格式输出 template bool OutputSMatrix(T M) { int i, j, k = 1; for (i = 0; i < M
rows; i++) { for (j = 0; j < M
cols; j++) { if ((M
data[k]
r-1) == i