有大牛知道链表的连接嘛

#include<stdio.h>
#include<math.h>
#define MaxCol 10
typedef struct Node1
{
	ElemType data[MaxCol];
	struct Node1 * next;
}Dlist;
typedef struct Node2
{
	int Row,Col;
	Dlist *next;
}HLIst;
void CreateTable(HList * &h)
{
	int i,j;
	DList *r,*s;
	h=(HList * )malloc(sizeof(HList));
	printf("表的行数,列数;");
	scanf("%d%d",&h->Row,&h->Col);
	for(i=0;i<h->Row;i++)
	{
		printf("第%d行:",i+1);
		s=(DList * )malloc(sizeof(DList));
		for(j=0;j<h->Col;j++)
		scanf("%d",&s->data[j]);
		if(h->next==NULL)
			h->next=s;
		else 
			r->next=s;
		r=s;
	}
	r=->next=NULL;
}
void CreateTable(HList * &h)
{
	DList * pre=h->next,*p=pre->next;
	while(p!=NULL)
	{
		free(pre)
		pre=p; p=p->next;
	}
	free(pre);
	free(h);
}
void DispTable(HList *h)
{
	int j;
	Dlist *p=h->next;
	while(p!=h->NULL)
	{
		for(j=0;j<h->Col;j++)
		printf("%4d",p->data[j]);
		printf("\n");
		p=p->next;
	}
}
void LinkTable(HList * h1,HList * h2,HList * &h)
{
	int i,j,k;
	DList * p=h1->next,*q,*s,*r;
	printf("连接字段是:第1个表序号,第2个表序号:");
	scanf("%d%d",&i,&j);
	h=(HList *)malloc(sizeof(HList));
	h->Row=0;
	h->Col=h1->Col+h2-> Col;
	h->next=NULL;
	while(p!=NULL)
	{
		q=h2->next;
		while(q!=NULL)
		{
			if (p> data[i-1]==q->data[j-1])	
			{
				s=(DList *)malloc(sizeof(DList)	
			for(k=0;k<h1->Col;k++)
				s->data[k]=p->data[k];
			for(k=0;k<h2->Col;k++)
				s->data[h1->Col+k]=q->data[k];
			if(h->next==NULL)
				h ->next=s;
			else
				r->next=s;
				r=s;
				h->Row++;
			}
				q=q->next;
		}
			p=p->next;
	}
	r->next=NULL;
}
int main()
{
	HList *h1,*h2,*h;
	printf("表1:\n");
	CreatTable(h1);
	printf("表2:\n");
	CreatTable(h2);
	LinkTable(h1,h2,h);
	printf("连接结果表:\n");
	DispTable(h);
	Destroytable(h1);
	Destroytable(h2);
	Destroytable(h);
	return 1;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

马里马里廒

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值