解题思路:
注意事项:
参考代码:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct Stu1{
int num;
int score;
struct Stu1 *next;
}stu1;
stu1 *initLink(int n)
{
stu1 *p=(stu1*)malloc(sizeof(stu1));
stu1 *temp=p;
for(int i=0;i<n;i++)
{
stu1 *a=(stu1*)malloc(sizeof(stu1));
scanf("%d%d",&a->num,&a->score);
a->next=NULL;
temp->next=a;
temp=temp->next;
}
return p;
}
stu1 *hebing(stu1 *A,stu1 *B)
{
stu1 *temp1=A;
while(temp1->next!=NULL)
{
temp1=temp1->next;
}
stu1 *temp2=B;
temp1->next=temp2->next;
free(temp2);
return A;
}
int disply(stu1 *A)
{
stu1 *temp=A;
while(temp->next!=NULL)
{
temp=temp->next;
printf("%d %d\n",temp->num,temp->score);
}
return 0;
}
int sort(stu1 *C)
{
stu1 *temp1=NULL;
stu1 *temp2=NULL;
stu1 tmp;
stu1 tmp2;
for(temp1=C->next;temp1->next!=NULL;temp1=temp1->next)
{
for(temp2=temp1->next;temp2!=NULL;temp2=temp2->next)
{
if(temp1->num > temp2->num)
{
tmp=*temp1;
*temp1=*temp2;
*temp2=tmp;
tmp2.next=temp1->next;
temp1->next=temp2->next;
temp2->next=tmp2.next;}
}
}
return 0;
}
int destory(stu1 *C)
{
stu1 *temp=C;
stu1 *tmp;
while(temp!=NULL)
{
tmp=temp->next;
free(temp);
}
return 0;
}
int main()
{
int n,m;
scanf("%d%d",&n,&m);
stu1 *A;
stu1 *B;
stu1 *C;
A=initLink(n);
B=initLink(m);
C=hebing(A,B);
sort(C);
disply(C);
destory(C);
return 0;
}
0.0分
0 人评分