-2
這是我的code.I想知道爲什麼它不起作用。C++按升序排序鏈接列表
sll_node *sortList(sll_node *head)
{
int temp=head->value;
if(head!=NULL||temp>head->next->value)
{
head->value=head->next->value;
head->next->value=temp;
}
else
{
sortList(head->next);
sortList(head->next->next);
sortList(head->next);
}
return head;
}
你可以請指定你的意思是**「它不工作。」** –
請使用調試器。上述代碼中的問題不是太深奧。運行一個小列表,並在其上運行'sortList's操作會顯示答案。 – Pradhan
或者剛開始添加打印語句,這應該足以解決這個問題。在你已經解除引用'head'之後,你正在檢查'NULL' *。 – Praetorian