samedi 27 novembre 2021

Deleting all nodes inside a linked list

I've created this function, and I'm wanting to delete all of the nodes inside of the linked list. However, it doesn't seem to be working and only deletes the first node (?).

void deleteList(Node* &pTemp) {
    Node *pCurrent = pTemp;
    Node* next = NULL;

    while(pCurrent != NULL) {
        next = pCurrent -> nextNode;
        free(pCurrent);
        pCurrent = next;
    }
}

What can I do to make this delete every single node, but still have an empty list?

Aucun commentaire:

Enregistrer un commentaire