文章
37
粉丝
168
获赞
13
访问
287.2k
#include <bits/stdc++.h>
using namespace std;
typedef struct Node{
int n;
struct Node* next;
}Node,*Link;
Link createnode(int e){
Link node=(Link)malloc(sizeof(Node));
node->next=NULL;
node->n=e;
}
Link createlist(int s){
Link list=createnode(0);
Link p=list;
int num;
for(int i=0;i<s;i++){
cin>>num;
p->next=createnode(num);
p=p->next;
}
return list;
}
int main()
{
int s1,s2;
cin>>s1;
Link list1=createlist(s1);
cin>>s2;
Link list2=createlist(s2);
Link p2=list2->next;
while(p2!=NULL){
Link pn=p2->next;
Link p1=list1;
while(p1->next!=NULL && p1->next->n<p2->n) p1=p1->next;
p2->next=p1->next;
p1->next=p2;
p2=pn;
}
Link h=list1;
while(h->next!=NULL){
cout<<h->next->n<<' ';
h=h->next;
}
}
登录后发布评论
暂无评论,来抢沙发