1999-c-四

#include <stdio.h>

typedef struct student
{
    float grade;
    struct student *next;
} student;

struct student *SortLink(struct student *head)
{
    struct student *pre,*p,*pre_m,*m,*n;
    float min;//最小值
    n=NULL;//将指针变为空,用于区别是否为首次插入
    while(head->next!=NULL)
    {
        pre=head;
        p=head->next;//工作指针

        m=p;
        pre_m=pre;
        min=p->grade;//最小值信息初始化

        while(p!=NULL)
        {
            if(p->grade<min)
            {
                min=p->grade;
                m=p;//保留当前次最小值地址
                pre_m=pre;
            }
            p=p->next;
            pre=pre->next;
        }
        pre_m->next=m->next;//将最小值结点从当前链表移除
        if(n==NULL)//第一个结点
        {
            n=m;
        }
        else
        {
          m->next=n;
          n=m;//采用头插法
        }
    }
    return n;
}