×ܽ᣺ÈýÔª×é˳Ðò±íʾ·¨±íʾϡÊè¾ØÕóÓÐÒ»¶¨µÄ¾ÖÏÞÐÔ£¬ÌرðÊÇÔÚ¾ØÕóµÄ³Ë·¨µÄʱºò£¬·Ç³£¸´ÔÓ¡£Í·Îļþ#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.pdata[countm].col==j)){temp=M.pdata[countm].elem;countm++;}elseif((N.pdata[countn].row==i)&&(N.pdata[countn].col==j)){temp=N.pdata[countn].elem;countn++;}if(temp){if(count>memsize){Q->pdata=(Triple*)realloc(Q->pdata,(memsize+1)*sizeof(Triple));memsize£¨²Î¿¼£º£©43;=1;}Q->pdata[count].row=i;Q->pdata[count].col=j;Q->pdata[count].elem=temp;count++;temp=0;}}}Q->tnum=count-1;return0;}intSubMatrix(TSMatrix*Q,TSMatrixM,TSMatrixN){if(M.rnum!=N.rnum||M.cnum!=N.cnum){printf("can'tsub!\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.pdata[countm].col==j)){temp=M.pdata[countm].elem;countm++;}elseif((N.pdata[countn].row==i)&&(N.pdata[countn].col==j)){temp=-1*N.pdata[countn].elem;countn++;}if(temp){if(count>memsize){Q->pdata=(Triple*)realloc(Q->pdata,(memsize+1)*sizeof(Triple));memsize+=1;}Q->pdata[count].row=i;Q->pdata[count].col=j;Q->pdata[