莓吕的事少管 2022-05-19 17:40 采纳率: 75%
浏览 31
已结题

c语言 链表快速排列 报错

问题遇到的现象和发生背景
问题相关代码,请勿粘贴截图
typedef struct Student          //学生成绩结构体
{
    char name[50];
    int xuehao;
    double score[N];
    int ranking;
}student;

typedef struct Node  //链表结点 
{
    student stu;
    struct Node* next;
}Node, * PointNode;


void Quicksort(PointNode& tf, PointNode& p)//tf是链表头结点 p是链表尾结点
{
    PointNode i = tf;
    PointNode n=tf;
    PointNode m=tf;
    PointNode j = p;
    
    
    student t, temp;
    if (i == j)
        return;
    temp = i->stu;
    while (i != j)
    {
        while (j->stu.ranking >= temp.ranking && i != j)
        {
            for (n = tf; n != j; n = n->next)
                m = n;
            j = m;
        }
    
    while (i->stu.ranking <= temp.ranking && i != j)
        {
            i = i->next;
        }
        if (i != j)
        {
            t = i->stu;
            i->stu = j->stu;
            j->stu = t;
        }
    }
    tf->stu = i->stu;
    i->stu = temp;
    for (n = tf; n != i; n = n->next)
        m = n;

    Quicksort(tf, m);
    Quicksort(i->next, p);
}

运行结果及报错内容

img

我的解答思路和尝试过的方法
我想要达到的结果
  • 写回答

2条回答 默认 最新

  • 关注

    你要加个判断 n!=NULL

            for (n = tf; n!=NULL && n != j; n = n->next)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 5月28日
  • 已采纳回答 5月20日
  • 创建了问题 5月19日

悬赏问题

  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)