编写实现C=A×B操作的函数,设矩阵A、B和C均为采用压缩存储方式的n阶对称矩阵,矩阵元素均为整型。

来源:百度知道 编辑:UC知道 时间:2024/05/01 07:45:46
数据结构

#include <stdio.h>
#define MAXSIZE 100
#define MAXROW 100
typedef struct {
int row, col, e;
} Triple;
typedef struct {
Triple data[MAXSIZE+1];
int first[MAXROW+1];
int m, n, len;
} TsMatrix;
int MulSMatrix(TsMatrix *M, TsMatrix *N, TsMatrix *Q)
{
int qrow, qcol, p, q;
int num[MAXSIZE], position[MAXSIZE], qtemp[MAXSIZE];
if (M->n!=N->m) return 0;
Q->m=M->m; Q->n=N->n; Q->len=0;
if (M->len*N->len)
{

for (qrow=1; qrow<=Q->m; qrow++)
{
for (qcol=1; qcol<=Q->n; qcol++)
qtemp[qcol]=0;
Q->first[qrow]=Q->len+1;
for (p=M->first[qrow]; p<M->first[qrow+1]; p++)
for (q=N->first[M->data[p].col]; q<N->first[M->data[p].col+1]; q++)
qtemp[N->data[q].col]+=M->data[p].e*N->data[q].e;
for (qcol=1; qcol<=Q->n; qcol++)
if (qtemp[