ch4_3.txt
上传用户:lgb298
上传日期:2013-03-22
资源大小:1025k
文件大小:1k
源码类别:

软件工程

开发平台:

C/C++

  1. void crt_linkedmat(JD *rh[],JD *ch[],int *hs,int *ls)
  2. {  int m,n,i,r,c,v;
  3.    JD *p,*q,*s;
  4.    printf("Input m,n:");
  5.    scanf("%d,%d",&m,&n);
  6.    for(i=0;i<m;i++)  rh[i]=NULL;
  7.    for(i=0;i<n;i++)  ch[i]=NULL;
  8.    *hs=m;  *ls=n;
  9.    for(;;)
  10.    {  printf(Input r,c,v:");
  11.       scanf("%d,%d,%d",&r,&c,&v);
  12.       if(r==0 || c==0)  break;
  13.       if((r>m)||(c>n))  continue;
  14.       
  15.       s=(JD *)malloc(sizeof(JD));
  16.       s->row=r; s->col=c; s->val=v;
  17.       s->right=s->down=NULL;
  18.  
  19.       q=NULL;  p=rh[r-1];
  20.       while((p!=NULL)&&(c>p->col))
  21.       {  q=p;  p=p->right;  }
  22.       if(p==NULL)
  23.       {   if(q==NULL)   rh[r-1]=s;
  24.           else   q->right=s;
  25.       }
  26.       else if(c==p->col)
  27.       {  p->val=v;  free(s);  continue;  }
  28.       else
  29.       {  if(q==NULL)
  30.          {   rh[r-1]=s; s->right=p; }
  31.          else
  32.          {   s->right=p; q->right=s;  }      
  33.       }
  34.       q=NULL;  p=ch[r-1];
  35.       while((p!=NULL)&&(r>p->row))
  36.       {  q=p;  p=p->down;  }
  37.       if(p==NULL)
  38.       {   if(q==NULL)   ch[c-1]=s;
  39.           else   q->down=s;
  40.       }
  41.       else
  42.       {  if(q==NULL)
  43.          {   ch[c-1]=s; s->down=p; }
  44.          else
  45.          {   s->down=p; q->down=s;  }      
  46.       }
  47.    }
  48. }