ch4_3.txt
上传用户:lgb298
上传日期:2013-03-22
资源大小:1025k
文件大小:1k
- void crt_linkedmat(JD *rh[],JD *ch[],int *hs,int *ls)
- { int m,n,i,r,c,v;
- JD *p,*q,*s;
- printf("Input m,n:");
- scanf("%d,%d",&m,&n);
- for(i=0;i<m;i++) rh[i]=NULL;
- for(i=0;i<n;i++) ch[i]=NULL;
- *hs=m; *ls=n;
- for(;;)
- { printf(Input r,c,v:");
- scanf("%d,%d,%d",&r,&c,&v);
- if(r==0 || c==0) break;
- if((r>m)||(c>n)) continue;
-
- s=(JD *)malloc(sizeof(JD));
- s->row=r; s->col=c; s->val=v;
- s->right=s->down=NULL;
-
- q=NULL; p=rh[r-1];
- while((p!=NULL)&&(c>p->col))
- { q=p; p=p->right; }
- if(p==NULL)
- { if(q==NULL) rh[r-1]=s;
- else q->right=s;
- }
- else if(c==p->col)
- { p->val=v; free(s); continue; }
- else
- { if(q==NULL)
- { rh[r-1]=s; s->right=p; }
- else
- { s->right=p; q->right=s; }
- }
- q=NULL; p=ch[r-1];
- while((p!=NULL)&&(r>p->row))
- { q=p; p=p->down; }
- if(p==NULL)
- { if(q==NULL) ch[c-1]=s;
- else q->down=s;
- }
- else
- { if(q==NULL)
- { ch[c-1]=s; s->down=p; }
- else
- { s->down=p; q->down=s; }
- }
- }
- }