大家帮忙看下我写的这个C程序如何改才对??

来源:百度知道 编辑:UC知道 时间:2024/09/25 11:21:10
程序如下:
#include<stdio.h>
#define NULL 0
struct student
{
int number;
int score;
struct student *next;
};
void main()
{
struct student *scat(struct student *,struct student *);
struct student *sort(struct student *);
struct student *head,*head1,*head2,*p;
struct student a1,a2,a3,a4,b1,b2,b3;
a1.number=10102;a1.score=88;
a2.number=10101;a2.score=87;
a3.number=10104;a3.score=85;
a4.number=10107;a4.score=67;
b1.number=10108;b1.score=55;
b2.number=10106;b2.score=76;
b3.number=10103;b3.score=96;
a1.next=&a2;
a2.next=&a3;
a3.next=&a4;
a4.next=NULL;
head1=&a1;
head2=&b1;
b1.next=&b2;
b2.next=&b3;
b3.next=NULL;
p=head1;
printf("the a link are:\n");
do
{
printf("%d\t%d\n",p->number,p->score);
p=p->next;
}while(p!=NULL);
printf(&quo

排序出问题了 这样修改即可

struct student *sort(struct student *head)
{
struct student *p0,*p1,*p2,*p3;
int x;
p0=head;
do
{
p1=p2=p3=head; //修改处1**********************************
p1=p1->next;
while(p1!=NULL) //修改处2**********************************
{
if(p1->number<p2->number)
{
if(p2==head)
{
head=p1;
p2->next=p1->next;
p1->next=p2;
}
else
{
/* if(p1->next==NULL) */
/* { */
/* p2->next=NULL; */
/* p1->next=p2; */
/* p3->next=p1; */
/* } */
/* else */
/* { */
p2->next=p1->next;
p1->next=p2;
p3->next=p1;
/* } */
}
}
p3=p2;