学生成绩管理系统—排序部分
- 学生成绩管理系统其他部分参考我的前一篇文章(前一篇文章链接在文末), 本文只叙述排序部分的代码 ;
- 排序方法: 冒泡排序 ;
代码展示
int CSDN(p_Node p_Head)//因为我用的有头链表写的数据结构, 所以要传入头
{
p_Node curNode = p_Head->next;
p_Node nextNode = curNode->next;
while (curNode != NULL)
{
while (nextNode != NULL)
{
if (curNode->Stu->score[3] < nextNode->Stu->score[3])
{
p_Data temp = curNode->Stu;
curNode->Stu = nextNode->Stu;
nextNode->Stu = temp;
}
//cout << "i" << endl;
nextNode = nextNode->next;
}
//cout << "j" << endl;
if (curNode != NULL)
{
curNode = curNode->next;
}
if (curNode != NULL && curNode->next != NULL)//防止节点溢出产生错误
{
nextNode = curNode->next;
}
}
cout << endl << "排序完成..." << endl;
return Ok;
}
- 这就是一个冒泡排序的方法, 只不过用的链表实现;
- 如有疑问, Q我;
- 该管理系统其他部分在下面链接这个文章中;
https://blog.csdn.net/qq_46282869/article/details/124431782?spm=1001.2014.3001.5501
- 文章仅作为自己的笔记和成长记录, 仅供参考…