當我運行此代碼時,它return
是正確的數字,但它不是delete
它之後。從鏈表中刪除最後一個節點C++
我嘗試了幾個其他功能,他們也不工作。 我的功能有問題嗎?還是我應該在外面看?
int Stack::remove()
{
clean = head; //clean is what it to be deleted. Head is the beginning
while (clean->next != NULL) //stop at the end of list
{
clean = clean->next; //move it along
}
return clean->number; //this gives me the right number
delete clean; //but when I print list in main, last item is still there
clean = NULL; //something about dangling pointers
}