解题思路:
注意事项:
参考代码:
#include<iostream>
using namespace std;
struct student
{
int id;
int score;
student *next;
};
student *create(int n)
{
student *head=NULL,*p1,*p2;
p1=new student;
head=p1;
for(int i=0;i<n;i++)
{
cin>>p1->id>>p1->score;
p2=p1;
p1=new student;
p2->next=p1;
}
p1->next=NULL;
return head;
}
student *sort(student *head1,student *head2,int n,int m)
{
student *p[100];
student *t;
p[0]=head1;
for(int i=1;i<n;i++)
{
p[i]=p[i-1]->next;
}
p[n]=head2;
for(int i=n+1;i<n+m;i++)
{
p[i]=p[i-1]->next;
}
for(int i=0;i<n+m-1;i++)
for(int j=0;j<n+m-i-1;j++)
{
if(p[j]->id>p[j+1]->id)
{
t=p[j];
p[j]=p[j+1];
p[j+1]=t;
}
}
for(int i=n+m;i>0;i--)
{
p[i-1]->next=p[i];
}
return p[0];
}
void print(student *head,int n)
{
student *p=head;
for(int i=1;i<n+1;i++)
{
cout<<p->id<<" "<<p->score<<endl;
p=p->next;
}
}
int main()
{
int n,m;
cin>>n>>m;
student *head1,*head2,*p;
head1=create(n);
head2=create(m);
head1=sort(head1,head2,n,m);
print(head1,n+m);
return 0;
}
0.0分
1 人评分
P1002 (C语言代码)浏览:972 |
简单的a+b (C语言代码)浏览:335 |
【金明的预算方案】 (C++代码)浏览:937 |
水仙花 (C语言代码)浏览:1047 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:505 |
C语言程序设计教程(第三版)课后习题10.3 (C语言代码)浏览:1909 |
C二级辅导-分段函数 (C语言代码)浏览:593 |
C二级辅导-公约公倍 (C语言代码)浏览:482 |
C语言程序设计教程(第三版)课后习题12.1 (C语言代码)浏览:642 |
C二级辅导-统计字符 (C语言代码)浏览:629 |