【发布时间】:2019-03-14 22:40:54
【问题描述】:
我正在尝试对链表进行排序,但在排序时出现此分段错误,尝试调试但无法找到问题。
这里是排序函数:
void Asort(struct lol **head_ref)
{
cout<<"Entered in asort function\n";
/// Sorting Asendingly
int temp1; /// to store the temp value
struct lol* temp = *head_ref;
struct lol* next;
while(temp!=NULL)
{
cout<<"Entered in while loop until null\n";
next=temp->next;
cout<<"log: " << next->element;
if(temp->element > next->element && next!=NULL)
{
cout<<"Entered in If condition inside while loop\n";
temp1=next->element;
next->element=temp->element;
temp->element=temp1;
}
temp=temp->next;
}
cout<<"Sorted Asending Successfully\n";
}
这是调用语句: 分类(*head)
【问题讨论】:
标签: singly-linked-list segmentation-fault