文章
79
粉丝
221
获赞
46
访问
202.7k
#include <iostream>
using namespace std;
typedef struct LNode{
int data;
struct LNode *next;
}LNode,*List;
int main() {
List L1=new LNode,L2=new LNode;
LNode *r1=L1,*r2=L2;
L1->next=NULL,L2->next=NULL;
int s1,s2;
cin>>s1;
for(int i=0;i<s1;i++){
LNode *k = new LNode;
cin>>k->data;
k->next=r1->next;
r1->next=k;
r1=k;
}
cin>>s2;
for(int i=0;i<s2;i++){
LNode *k = new LNode;
cin>>k->data;
k->next=r2->next;
r2->next=k;
r2=k;
}
LNode *p1=L1->next,*p2=L2->next;
while(p1&&p2){
if(p1->data<p2->data){
cout<<p1->data<<" ";
p1=p1->next;
}else{
cout<<p2->data<<" ";
p2=p2->next;
}
}
while(p1){
cout<<p1->data<<" ";
p1=p1->next;
}
while(p2){
cout<<p2->data<<" ";
p2=p2->next;
}
return 0;
}
登录后发布评论
暂无评论,来抢沙发