这是一个矩阵朴素转置的代码,但是最后一个元素老是显示为0,求指示,谢谢了
```c++
#include <stdio.h>
#define MAXSIZE 100
#define OK 1
#define ERROR 0
#define ELEMTYPE int
typedef struct {
int i; //行
int j; //列
ELEMTYPE e; //元素
}Triple;
typedef struct {
Triple data[MAXSIZE+1];
int mu, nu, tu;
}TSmatrix;
void display(TSmatrix *s);
void trans(TSmatrix *s,TSmatrix *x);
int main(void)
{
TSmatrix s,x;
s.mu = 3;
s.nu = 3;
s.tu = 3;
s.data[0].i = 3;
s.data[0].j = 3;
s.data[0].e = 6;
s.data[1].i = 2;
s.data[1].j = 3;
s.data[1].e = 8;
s.data[2].i = 2;
s.data[2].j = 1;
s.data[2].e = 4;
display(&s);
trans(&s,&x);
display(&x);
return 0;
}
void display(TSmatrix *s)
{
for (int i = 1; i <= s->mu; i++)
{
for (int j = 1; j <= s->nu; j++)
{
int value = 0; //用来判断是否到了指定的(i,j)位置
for (int k = 0; k < s->tu; k++)//遍历数组中的三元表值
{
if (s->data[k].i == i && s->data[k].j == j) //若遍历至指定(i,j)就打印元素值
{
value = 1;
printf("%d ", s->data[k].e);
break;
}
}
if(value==0) //若不为三元表中存储的值就打印0
printf("%d ", 0);
}
printf("\n");
}
}
void trans(TSmatrix *s,TSmatrix *x)
{
int p, q, col;
x->mu=s->nu;
x->nu=s->mu;
x->tu=s->tu;
if (x->tu)
{
q = 1;
for (col = 1; col <= s->nu; ++col)
for (p = 1; p <= s->tu; ++p)
if (s->data[p].j == col)
{
x->data[q].i = s->data[p].j;
x->data[q].j = s->data[p].i;
x->data[q].e = s->data[p].e;
++q;
}
}
return;
}
```