return current->next->card; // return !!
delete current->next; // so this will never be executed
current->next = NULL;
更新
正如下面的評論請求進一步的輸入,在這裏是我試圖保持原始原則的更新。
if (front == nullptr) // Special handling of empty list
{
// Nothing to return - add error handling - throw exception perhaps
// or:
return ???; // A default card perhaps
}
if (front->next == nullptr) // Special handling of list with one element
{
// Only one element
Card a = front->card;
delete front;
front = nullptr;
return a;
}
Card_Node *current;
current = front;
while (current->next->next != NULL) // Iterate to find last element
{
current = current-> next;
}
// Now current->next is last element, i.e. the one to remove
Card a = current->next->card;
delete current->next;
current->next = NULL;
return a;
改變了它,但它仍然不會刪除..... \t \t \t Card_Node *電流; \t current = front; \t \t 而(!電流 - >下一步 - >下一= NULL){ \t \t \t 當前\t =電流 - >下; \t} \t \t \t卡a =當前 - >下一個 - >卡; \t \t return a; \t \t delete current-> next; \t \t current-> next = NULL; \t \t } – Lauren
有沒有原因,你不使用'std :: list'? –