TSMatrix.cpp
#define M 6
#define N 7
#include "TSMatrix.h"
int main()
{
TSMatrix t;
ElemType x;
ElemType a[M][N]={
{0,12,9,0,0,0,0},{0,0,0,0,0,0,0},{3,0,0,0,0,14,0},{0,0,24,0,0,0,0},{0,18,0,0,0,0,0},{15,0,0,-7,0,0,0}};
CreatMat(t,a);
printf("三元组t表示:\n");DispMat(t);
printf("执行A[4][3]=5\n");
Value(t,5,4,3);
printf("三元组t表示:\n");DispMat(t);
printf("求A[2][0]的值\n");
Assign(t,x,2,0);
printf("x=%d\n",x);
return 0;
}
TSMatrix.h
#include <iostream>
using namespace std;
#define MaxSize 100
typedef char ElemType;
typedef struct
{
int r;
int c;
ElemType d;
} TupNode;
typedef struct
{
int rows;
int cols;
int nums;
TupNode data[MaxSize];
} TSMatrix;
void CreatMat(TSMatrix &t,ElemType A[M][N])
{
int i,j;
t.rows=M;t.cols=N;t.nums=0;
for (i=0;i<M;i++)
{
for (j=0;j<N;j++)
if (A[i][j]!=0)
{
t.data