建立并合并两个循环链表 但是最后没有输出哪位大神帮忙看下
#include<iostream.h>#include<stdlib.h>
int n;
typedef struct node{
int data;
int length;
struct node *next;
}node, * list;
void createlist(list *L)
{int i;
*L=(list)malloc(sizeof(node));
(*L)->next=NULL;
list p,r;
r=*L;
cout<<"enter data's number:";
cin>>n;
(*L)->length=n;
cout<<"enter data:";
for(i=0;i<n;i++)
{
p=(list)malloc(sizeof(node));
cin>>p->data;
r->next=p;
r=p;
}
r->next=*L;
}
void outputlist(list *L)
{
cout<<"your list is:"<<endl;
for(int i=0;i<n;i++)
{cout<<(*L)->next->data<<"\t";
*L=(*L)->next;
}
cout<<endl;
}
void mergelist(list *L1,list *L2)
{list L3;
L3=(*L1)->next;
list q,s;
q=*L1;
s=*L2;
while(q->next!=*L1)
{q=q->next;}
while(s->next!=*L2)
{s=s->next;}
s->next=*L1;
q->next=(*L2)->next;
free(*L2);
cout<<"the news cirsulate list is:";
n=(*L1)->length+(*L2)->length;
for(int i=0;i<n;i++)
{
cout<<L3->data;
(L3)=(L3)->next;
}
cout<<endl;
}
int main()
{list L1,L2;
createlist(&L1);
outputlist(&L1);
createlist(&L2);
outputlist(&L2);
mergelist(&L1,&L2);
return 0;
}