#include
#define MAXSIZE 30
typedef int ElemType;
typedef struct {
int i, j;
ElemType e;
}Triple;
typedef struct {
Triple data[MAXSIZE + 1];
int mu, nu, tu;
}TSMatrix;
void CreateTSMatrix(TSMatrix *T, int M[][7], int mu, int nu, int tu) {
T->mu = mu;
T->nu = nu;
T->tu = tu;
int q = 1;
for(int i=0; i
for(int j=0; j
if(M[i][j]!=0) {
T->data[q].i = i;
T->data[q].j = j;
T->data[q].e = M[i][j];
q++;
}
}
}
void TransposeSMatrix(TSMatrix *M, TSMatrix *T) {
T->mu = M->nu;
T->nu = M->mu;
T->tu = M->tu;
if(T->tu) {
int q = 1;
for(int col=0; colnu; col++)
for(int p=1; p<=M->tu; p++)
if(M->data[p].j==col) {
T->data[q].i = M->data[p].j;
T->data[q].j = M->data[p].i;
T->data[q].e = M->data[p].e;
q++;
}
}
}
void PrintTSMatrix(TSMatrix *T) {
printf("the triple matrix is: /n");
for(int i=0; itu; i++) {
printf("%d, %d, %d/n", T->data[i+1].i, T->data[i+1].j, T->data[i+1].e);
}
}
int main() {
int Matrix[][7] = {{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}};
TSMatrix M;
TSMatrix T;
CreateTSMatrix(&M, Matrix, 7, 6, 8);
PrintTSMatrix(&M);
TransposeSMatrix(&M, &T);
PrintTSMatrix(&T);
}