#include<stdio.h>
#include<malloc.h>
typedef int DataType;
typedef struct node
{
DataType data;
struct node *next;
}LinkNode,*LinkList;
LinkNode *CreateList(void)
{
LinkList head,q,p;
int flag=1;
DataType data;
head=p=(LinkNode *)malloc(sizeof(LinkNode));
while(flag)
{
scanf("%d",&data);
if(data>0)
{
q=(LinkNode *)malloc(sizeof(LinkNode));
q->data=data;
p->next=q;
p=q;
}
else
{
flag=0;
p->next=head;
}
}
return head;
}
void PrintList(LinkNode *head)
{
LinkList p;
p=head->next;
while(p != head)
{
printf("%-3d",p->data);
p=p->next;
}
printf("\n");
}
LinkNode *Merge_1(LinkList la,LinkList lb)
{
LinkNode *p,*q;
p=la;
q=lb;
while(p->next != la)
p=p->next;
while(q->next != lb)
q=q->next;
q->next=la;
p->next=lb->next;
free(lb);
return la;
}
int main(int args,int *argv[])
{
LinkNode *head1,*head2;
printf("please input the listA: \n");
head1=CreateList();
printf("please input the listB: \n");
head2=CreateList();
Merge_1(head1,head2);
PrintList(head1);
}
循环单链表的合并
最新推荐文章于 2023-12-13 20:09:58 发布