大家帮忙看看这个十字链表算法问题出在哪里?
#include <stdio.h>#include <stdlib.h>
typedef struct OLNode
{
int i,j;
int e;
struct OLNode *right,*down;
}OLNode,*OLink;
typedef struct
{
OLink *rhead,*chead;
int mu,nu,tu;
}CrossList;
void CreatSMatrix_OL(CrossList *M)
{
int i,j,e;
int m,n,t;
OLink p,q;
printf("请输入M的行数、列数和非零元的个数:\n");
scanf("%d%d%d",&m,&n,&t);
M->mu=m,M->nu=n,M->tu=t;
if(!(M->rhead=(OLink *)malloc((m+1)*sizeof(OLink))))
exit(0);
if(!(M->chead=(OLink *)malloc((n+1)*sizeof(OLink))))
exit(0);
for(i=1;i<=m;i++)
M->rhead[i]=NULL;//
for(j=1;j<=n;j++)
M->chead[j]=NULL;
printf("请按任意次序录入非零元的三元组数据,格式(行数 列数 非零元):\n");
while(t>0)
{
scanf("%d%d%d",&i,&j,&e);
if(!(p=(OLNode *)malloc(sizeof(OLNode))))
exit(0);
p->i=i;p->j=j;p->e=e;
if(M->rhead[i]==NULL||M->rhead[i]->j>j)
{
p->right=M->rhead[i];
M->rhead[i]=p;
}
else
{
for(q=M->rhead[i];(q->right)&&(q->right->j<j);q=q->right)
p->right=q->right;q->right=p;
}
if(M->chead[j]==NULL||M->chead[j]->i>i)
{
p->down=M->chead[j];
M->chead[j]=p;
}
else
{
for(q=M->chead[i];(q->down)&&(q->down->i<i);q=q->down)
p->down=q->down;q->down=p;
}
t--;
}
}
void main()
{
CrossList *M=(CrossList *)malloc(sizeof(CrossList));
CreatSMatrix_OL(M);
}
比如说像上面那样输入数据就有问题?