总结:三元组顺序表示法表示稀疏矩阵有一定的局限性,特别是在矩阵的乘法的时候,非常复杂。头文件#ifndefSYZHEAD_H_INCLUDED#defineSYZHEAD_H_INCLUDED#include<stdio.h>#include<stdlib.h>typedefintElemType;typedefstruct{introw;intcol;ElemTypeelem;}Triple;typedefstruct{Triple*pdata;intrnum;intcnum;inttnum;}TSMatrix;intCreateMatrix(TSMatrix*M);intDestroyMatrix(TSMatrix*M);intPrintMatrix(TSMatrix*M);intPrintTriple(TSMatrix*M);intCopyMatrix(TSMatrix*Dest,TSMatrixSource);intTransposeMatrix(TSMatrix*Dest,TSMatrixSource);intAddMatrix(TSMatrix*Q,TSMatrixM,TSMatrixN);intSubMatrix(TSMatrix*Q,TSMatrixM,TSMatrixN);intMultMatrix(TSMatrix*Q,TSMatrixM,TSMatrixN);#endif//SYZHEAD_H_INCLUDED函数的实现#include"syzhead.h"intCreateMatrix(TSMatrix*M){printf("pleaseinputthernum,cnum,tnumofM\n");scanf("%d%d%d",&M->rnum,&M->cnum,&M->tnum);M->pdata=(Triple*)malloc((M->tnum+1)*sizeof(Triple));if(!M->pdata){exit(1);}intcount=1;while(count<=M->tnum){scanf("%d%d%d",&M->pdata[count].row,&M->pdata[count].col,&M->pdata[count].elem);---本文来源于网络,仅供参考,勿照抄,如有侵权请联系删除---if(M->pdata[count].row>M->rnum||M->pdata[count].col>M->cnum){printf("IndexERROR!\n");exit(1);}count++;}return0;}intDestroyMatrix(TSMatrix*M){if(!M->pdata){printf("ERROR!\n");exit(1);}free(M->pdata);M->pdata=NULL;M->cnum=0;M->rnum=0;M->tnum=0;return0;}intPrintMatrix(TSMatrix*M){inti,j;intcount=1;for(i=1;i<=M->rnum;i++){for(j=1;j<=M->cnum;j++){if((M->pdata[count].row==i)&&(M->pdata[count].col==j)){printf("%d\t",M->pdata[count].elem);count++;}else{printf("0\t");}}printf("\n");}return0;}intPrintTriple(TSMatrix*M){inti;for(i=1;i<=M->tnum;i++){printf("%d\t%d\t%d\n",M->pdata[i].row,M->pdata[i].col,M->pdata[i].elem);---本文来源于网络,仅供参考,勿照抄,如有侵权请联系删除---}return0;}intCopyMatrix(TSMatrix*Dest,TSMatrixSource){Dest->cnum=Source.cnum;Dest->rnum=Source.rnum;Dest->tnum=Source.tnum;Dest->pdata=(Triple*)malloc((Dest->tnum+1)*sizeof(Triple));inti=1;while(i<=Dest->tnum){Dest->pdata[i].row=Source.pdata[i].row;Dest->pdata[i].col=Source.pdata[i].col;Dest->pdata[i].elem=Source.pdata[i].elem;i++;}return0;}intTransposeMatrix(TSMatrix*Dest,TSMatrixSource){Dest->rnum=Source.cnum;Dest->cnum=Source.rnum;Dest->tnum=Source.tnum;Dest->pdata=(Triple*)malloc((Dest->tnum+1)*sizeof(Triple));inti;intcol;intcount=1;for(col=1;col<=Source.cnum;col++){for(i=1;i<=Source.tnum;i++){if(Source.pdata[i].col==col){Dest->pdata[count].row=Source.pdata[i].col;Dest->pdata[count].col=Source.pdata[i].row;Dest->pdata[count].elem=Source.pdata[i].elem;count++;}}}return0;}intAddMatrix(TSMatrix*Q,TSMatrixM,TSMatrixN){if(M.rnum!=N.rnum||M.cnum!=N.cnum){printf("can'tadd!\n");exit(1);}Q->cnum=M.cnum;Q->rnum=M.rnum;---本文来源于网络,仅供参考,勿照抄,如有侵权请联系删除---intmemsize=M.tnum+N.tnum+1;Q->pdata=(Triple*)malloc(memsize*sizeof(Triple));if(!Q->pdata){printf("ERROR!\n");exit(1);}inti;intj;intcount=1;intcountm=1;intcountn=1;inttemp=0;for(i=1;i<=Q->rnum;i++){for(j=1;j<=Q->cnum;j++){if((M.pdata[countm].row==i)&&(M.pdata[countm].col==j)&&(N.pdata[countn].row==i)&&(N.pdata[countn].col==j)){temp=M.pdata[countm].elem+N.pdata[countn].elem;countm++;countn++;}elseif((M.pdata[countm].row==i)&&(M.pda...