#include<iostream>
using namespace std;
typedef struct head
{
int a;
struct head *next;
}NLode;
void intial(NLode **head)
{
*head=(NLode *)malloc(sizeof(NLode));
(*head)->next=NULL;
}
void insert(NLode *head,int a)
{
NLode *p,*q;
p=head;
q=(NLode*)malloc (sizeof(NLode));
while(p->next!=NULL)
{
p=p->next;
}
q->a=a;
q->next=p->next;
p->next=q;
}
void printSL(NLode *head)
{
NLode *p;
p=head->next;
while(p!=NULL)
{
cout<<p->a<<" "<<endl;
p=p->next;
}
}
void main()
{
NLode *head1,*head2;
intial(&head1);
intial(&head2);
int a,b,num=0,i;
cin>>a;
cin>>b;
for(i=0;i<a;i++)
{
cin>>num;
insert(head1,num);
}
num=0;
for(i=0;i<b;i++)
{
cin>>num;
insert(head2,num);
}
cout<<"A:"<<endl;
printSL(head1);
cout<<"B:"<<endl;
printSL(head2);
system("pause");
}
带头结点链表的实现
最新推荐文章于 2024-04-26 08:00:00 发布