当我运行此代码时,它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
}