哪位大神能给我解释一下下面的程序啊,急求!!!最好是每行都做注释 20
#include"stdio.h"#defineMAXSIZE10000typedefintElemType;typedefstruct{introw,col;ElemT...
#include "stdio.h"
#define MAXSIZE 10000
typedef int ElemType;
typedef struct
{ int row,col;
ElemType v;
}Triple;
typedef struct
{ Triple data[MAXSIZE];
int m,n,t;
}TriTable;
/*三元组相乘*/
void MultS(TriTable *A,TriTable *B,TriTable *C)
{ int k,p,crow,brow,q,ccol;
int num[MAXSIZE],pos[MAXSIZE],ctemp[MAXSIZE];
if (A->n==B->m)
{ for(k=1;k<=B->m;k++)
num[k]=0;
for(k=1;k<=B->t;k++)
num[B->data[k].row]++;
pos[1]=1;
for(k=2;k<=B->t;k++)
pos[k]=pos[k-1]+num[k-1];
pos[1+B->t]=pos[B->t]+1;
C->m=A->m; C->n=B->n; C->t=0; p=1;
while(p<=A->t)
{crow=A->data[p].row;
for(k=1;k<=C->n;k++)
ctemp[k]=0;
while (p<=A->t&&A->data[p].row==crow)
{
brow=A->data[p].col;
for(q=pos[brow];q<=pos[brow+1]-1;q++)
{ ccol=B->data[q].col;
ctemp[ccol]=ctemp[ccol]+A->data[p].v*B->data[q].v;
}
p=p+1;
}
for(ccol=1;ccol<=B->n;ccol++)
if(ctemp[ccol]!=0)
{ C->t=C->t+1;
C->data[C->t].row=crow;
C->data[C->t].col=ccol;
C->data[C->t].v=ctemp[ccol];
}
}
}else printf("俩个矩阵不能相乘");return;
} 展开
#define MAXSIZE 10000
typedef int ElemType;
typedef struct
{ int row,col;
ElemType v;
}Triple;
typedef struct
{ Triple data[MAXSIZE];
int m,n,t;
}TriTable;
/*三元组相乘*/
void MultS(TriTable *A,TriTable *B,TriTable *C)
{ int k,p,crow,brow,q,ccol;
int num[MAXSIZE],pos[MAXSIZE],ctemp[MAXSIZE];
if (A->n==B->m)
{ for(k=1;k<=B->m;k++)
num[k]=0;
for(k=1;k<=B->t;k++)
num[B->data[k].row]++;
pos[1]=1;
for(k=2;k<=B->t;k++)
pos[k]=pos[k-1]+num[k-1];
pos[1+B->t]=pos[B->t]+1;
C->m=A->m; C->n=B->n; C->t=0; p=1;
while(p<=A->t)
{crow=A->data[p].row;
for(k=1;k<=C->n;k++)
ctemp[k]=0;
while (p<=A->t&&A->data[p].row==crow)
{
brow=A->data[p].col;
for(q=pos[brow];q<=pos[brow+1]-1;q++)
{ ccol=B->data[q].col;
ctemp[ccol]=ctemp[ccol]+A->data[p].v*B->data[q].v;
}
p=p+1;
}
for(ccol=1;ccol<=B->n;ccol++)
if(ctemp[ccol]!=0)
{ C->t=C->t+1;
C->data[C->t].row=crow;
C->data[C->t].col=ccol;
C->data[C->t].v=ctemp[ccol];
}
}
}else printf("俩个矩阵不能相乘");return;
} 展开
1个回答
2013-01-18
展开全部
这神马程序
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询