#include<stdio.h>
#include<stdlib.h>
#define N 100
typedef struct node
{
int row, col;
int v;
struct node *r, *d;
}*link;
typedef struct crosslist
{
link rowhead[N], colhead[N];
int rows, cols, nums;
}*list;
int i, j;
list init(list cl);
list copy(list s1);
list add(list a, list b);
list sub(list s1, list s2);
void output(list cl);
list init(list cl)
{
link p, q, s;
int n, m, data;
cl=(list)malloc( sizeof(struct crosslist) );
if( !cl )
{
printf("\n无法生成十字链表\n");
return 0;
}
printf("\n矩阵总行数: ");
scanf("%d", &n);
printf("\n矩阵总列数: ");
scanf("%d", &m);
cl->rows=n;
cl->cols=m;
cl->nums=0;
for(i=0; i<n; i++)
{
cl->rowhead[i]=(link )malloc( sizeof(struct node) );
cl->rowhead[i]->r=NULL;
}
for(j=0; j<m; j++)
{
cl->colhead[j]=(link )malloc( sizeof(struct node) );
cl->colhead[j]->d=NULL;
}
for(i=0; i<n; i++)
{
printf("\n第%d行:", i+1);
q=cl->rowhead[i];
for(j=0; j<m; j++)
{
scanf("%d", &data);
if(data != 0)
{
p=(link)malloc( sizeof(struct node) );
p->v=data;
p->row=i+1;
p->col=j+1;
cl->nums++;
p->r=q->r;
q->r=p;
q=p;
s=cl->colhead[j];
while( s->d )
s=s->d;
p->d=s->d;
s->d&#
C语言:十字链表的相加相减
最新推荐文章于 2023-10-29 16:08:29 发布