链表的排序(结点) 为什么第一行不参与排序??
/* Note:Your choice is C IDE 同学通讯录*/#include "stdio.h"#include<stdlib.h>#include<string.h>struct stu{ long num; //学号 char name[20]; //姓名 char sex; //性别 long phone; //电话号码 struct stu *next;};struct stu *creat_list() // 建立链表{ struct stu *head,*q,*p; int i; for(i=0;i<3;i++) { q=(struct stu *)malloc(sizeof(struct stu)); printf("请输入第%d个待处理数据:\n学号 姓名 性别 电话 (中间空格隔开)\n",i+1); scanf("%ld %s %c %ld",&q->num,&q->name,&q->sex,&q->phone); if(i==0) p=head=q; else { p->next=q; p=q; } } p->next=NULL; return head;}void print(struct stu *head) //输出链表 { struct stu *p; int i; p=head; printf("序号\t学号\t\t姓名\t\t性别\t\t电话\n"); for(i=0;p!=NULL;i++) { printf("%d\t%ld\t\t%s\t\t%c\t\t%ld\n",i+1,p->num,p->name,p->sex,p->phone); p=p->next; }}struct stu *paixu(struct stu *head) //链表的排序{ struct stu *pra,*pa,*prb,*pb; pra=head; pa=pra->next; while(pa!=NULL) { prb=pa; pb=prb->next; while(pb!=NULL) { if(pb->num<pa->num) { prb->next=pb->next; pb->next=pa; pra->next=pb; pa=pb; pb=prb->next; continue; } prb=pb; pb=pb->next; } pra=pa; pa=pa->next; } return head;}main(){ struct stu *student; student=creat_list(); printf("输出链表\n"); print(student); student=paixu(student); printf("排序结果\n"); print(student);}