C语言链表问题

2020-06-29 11:21发布

不知道为什么经过排序后打出来的成绩单就变成两项了,请大佬们帮忙看看

//对成绩进行排序
struct stu *rank_info(struct stu *head)
{
struct stu *p, *q, *r, *o, *s, *t;
int n = 1, i;
while(n != 0)
{
n = 0;
for (p = head; p->next != NULL; o = p, p = q)
{
q = p->next;
r = q->next;
if (p->grades.g < q->grades.g)
{
++n;
if (p = head) head = q;
else o->next = q;
q->next = p;
p->next = r;
s = p;
p = q;
q = s;
}
}

}
//添加学生排名信息
for (t = head, i = 1; t != NULL; t = t->next)  
{
	t->grades.rank = i++;
	printf("%s", t->name);
}

return head;

}

1条回答
贼婆χ
2楼-- · 2020-06-29 11:31

if (p = head) 应该写成 if (p == head)

查看更多
登录 后发表回答