题目:已知a,b两个链表,每个链表中的结点包括学号、成绩。要求把两个链表合并,按学号升序排列。
// 链表和并.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "stdio.h"
#define SIZE 2
#define NULL 0
struct student
{
long num;
float score;
struct student *next;
};
int main(int argc, char* argv[])
{
struct student a,b,*p,*temp;
a.num=10011;a.score=89.5;
b.num=10010;b.score=98;
a.next=&b;
b.next=NULL;
p=&a;
while(p->next!=NULL)
{
temp=p->next;
if(p->num>temp->num)
{
p->num=(p->num+temp->num)-(temp->num=p->num);
p->score=(p->score+temp->score)-(temp->score=p->score);
}
p=p->next;
}
p=&a;
for(int i=0;i<SIZE;i++)
{
printf(" %ld %8.1f",p->num,p->score);
p=p->next;
}
return 0;
}
634

被折叠的 条评论
为什么被折叠?



