解题思路:
注意事项:
参考代码:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct student
{
int id;
int score;
struct student *next;
}NODE;
NODE *creatlist()
{
NODE *head = (NODE *)malloc(sizeof(NODE));
head->id = 0;
head->score = 0;
head->next = NULL;
return head;
}
void insertlist(NODE *head,int id,int score)
{
NODE *pnew = (NODE *)malloc(sizeof(NODE));
pnew->next = NULL;
pnew->id = id;
pnew->score = score;
pnew->next = head->next;
head->next = pnew;
}
void display(NODE *head)
{
NODE *p = head->next;
while(p != NULL)
{
printf("%d %d\n",p->id,p->score);
p = p->next;
}
}
void connect(NODE *head_a,NODE *head_b)
{
NODE *a = head_a->next;
NODE *b = head_b->next;
while(b != NULL)
{
insertlist(head_a,b->id,b->score);
b = b->next;
}
}
void delelist(NODE *head_a,int num)
{
NODE *p = head_a->next;
NODE *qian = head_a;
while(p != NULL)
{
if(p->id == num)
{
qian->next = p->next;
free(p);
break;
}
else
{
qian = p;
p = p->next;
}
}
}
void paixu(NODE *head_a,NODE *head)
{
NODE *p = head_a->next;
int min,s;
while(head_a->next != NULL)
{
p = head_a->next;
min = p->id;
s = p->score;
while(p != NULL)
{
if(min < p->id)
{
min = p->id;
s = p->score;
}
p = p->next;
}
insertlist(head,min,s);
delelist(head_a,min);
}
}
int main()
{
NODE *head_a = creatlist();
NODE *head_b = creatlist();
NODE *head = creatlist();
int n,m,i;
int id,score;
scanf("%d%d",&n,&m);
for(i = 0;i < n;i++)
{
scanf("%d%d",&id,&score);
insertlist(head_a,id,score);
}
for(i = 0;i < m;i++)
{
scanf("%d%d",&id,&score);
insertlist(head_b,id,score);
}
connect(head_a,head_b);
paixu(head_a,head);
display(head);
return 0;
}
0.0分
0 人评分
萨小坡 2018-03-24 09:22:57 |
。。。。。