c++ - 在 C++ 中对链表进行排序在运行时失败
问题描述
void head_insert(DomesticPtr& head, string firstNameD, string lastNameD, string province, float cgpaD, int researchScoreD, int idD)
{
DomesticPtr temp_ptr;
DomesticPtr temp2;
temp_ptr= new DomesticStudent(head, firstNameD, lastNameD, province,cgpaD,researchScoreD,idD);
temp2 = head->getLink();
temp2==temp_ptr;
head=temp_ptr;
if (head->getLink() == NULL)
return;
else
{
bubblesort(head);
}
}
void bubblesort(DomesticStudent* head)
{
int rsd;
int cgpad;
int p;
DomesticPtr tempc, tempd, tempe;
tempd=head;
tempe= head->getLink();
{
while(tempd != NULL)
{
rsd=compareResearchScore(tempd, tempe);
if (rsd==1)
{
tempc=head;
head->next=head;
head=tempc;
}// if
else if (rsd==0)
{
cgpad= compareCGPA(tempe,tempd);
if (cgpad==1)
{
tempc=head;
head->next=head;
head=tempc;
}// if (cgpad[k]>cgpad[k+1])
else if(cgpad==0)
{
p=compareProvince(tempd,tempe);
if(p==1)
{
tempc=head;
head->next=head;
head=tempc;
}// if (p[k]>p[k+1])
}//
}// else if cgpad[k]
}// else if rsd[k]
// }
// }
tempd = tempe;
}
int compareResearchScore(DomesticPtr RSA, DomesticPtr RSB)
{
if (RSB == NULL || RSA==NULL )
{
return 0;
}
if (RSA->researchScoreD==RSB->researchScoreD) //compares if is the same for domesetic students returns value for bubble sort
{
return 0;
}
if (RSA->researchScoreD > RSB->researchScoreD)
{
return 1;
}
if (RSA->researchScoreD< RSB->researchScoreD)
{
return -1;
}
}
我试图在每次插入新节点时对我的链表进行排序。它可以编译,但每次我尝试运行程序时,它都会卡在我试图打印我的列表的点上。我有一个析构函数,但没有复制构造函数或赋值运算符。head_insert 调用 sort 函数, sort 函数调用 compare 函数来接收整数输出,以便进行交换。我想比较研究,cgpa,然后是省。任何输入将不胜感激,这是一个项目,所以我不喜欢任何代码块,但如果你能指出我正确的方向或多个方向。
解决方案
推荐阅读
- python - 无法从 VisualStudioCode 终端运行 Python
- azure-active-directory - 使用 AD 自定义策略适用于 Azure 门户,但不适用于 .NET Core Web App
- neo4j - 如何在 NEO4J 中提高 LOAD CSV 的性能
- c# - 如何将 .jpg 包含到 dll 中?
- impala - 如何在 Superset 上模拟 Impala 查询
- asp.net-mvc-5 - 使用运行 Identity Server 4 的 ASP.NET CORE 3 身份验证服务器对 ASP.NET MVC 5 应用程序(针对 .net 4.5)进行身份验证
- wordpress - 使用远程数据库的 WordPress 本地开发工作速度非常慢
- firebase - 如何在 VS Code 中调试在文档 onDelete 上触发的 Firebase 云函数?
- android - 材料芯片 chipStrokeColor 未应用于芯片元素
- javascript - 您可以从导入的模块中调用函数而不调用 node.js 中的模块吗?