满意答案
yueleizizi
2013.05.23
采纳率:51% 等级:13
已帮助:37529人
#include
#include
typedef int Etype;
typedef struct OLnode
{
int i,j;
Etype e;
struct OLnode *right,*down;
}OLnode;
typedef struct
{
OLnode *rh[5],*ch[5];
int mu,nu,tu;
}Crosslist;
void creatMatrix(Crosslist *M);
void out_M(Crosslist M);
Crosslist ma;
int z;
int main()
{
creatMatrix(&ma);
out_M(ma);
return 0;
}
void out_M(Crosslist M)
{
int i;OLnode *p; char ch;
printf("\n m=%d t=%d\n",M.mu,M.nu,M.tu);
for(i=1; i<=M.mu; i++)
{
p=M.rh[i];
if(p) {
printf("\n i=%d",i);
while(p) { printf(" (%3d%3d%4d) ",p->i,p->j,p->e);
p=p->right;
}
}
printf("\n");
}
printf("\n 打回车键,返回。"); ch=getchar();
}
void creatMatrix(Crosslist *M)
{
int m,n,t,row,col,i,j;
Etype va; OLnode *p,*q,*s;
printf("\n m,n,t=?"); scanf("%d,%d,%d",&m,&n,&t);
for(i=1; i<=m;i++) M->rh[i]=NULL;
for(j=1; j<=n;i++) M->rh[j]=NULL;
M->mu=m; M->nu=n; M->tu=t;
for(i=1;i<=M->tu;i++)
{ printf("\n i,j,e=?"); scanf("%d,%d,%d",&row,&col,&va);
p=(OLnode*)malloc(sizeof(OLnode));
p->i=row; p->j=col; p->e=va;
q=M->rh[row]; s=q;
while(q!=NULL && q->j
right;}p->right=q;
if(q==M->rh[row]) M->rh[row]=p; else s->right=p;
q=M->ch[col];
while(q && q->i < row) {s=q;q=q->down;}
p->down=q;
if(q==M->ch[col]) M->ch[col]=p; else s->down=p;
}
}
00分享举报