I have assingment to implement double linked list in c++. I'm adding new node to list for example like this.
addToFront(){
node* tmp = new node();
tmp->data = value;
tmp->next = head;
head->prev = tmp;
head = tmp;
}
I've written funtion to delete node from list (I'm aware that I have to consider deleting from head and tail), but I'm not sure if it destroys the node. So this is my question. Will my code release resources after deleting node from list?
deleteNode(){
node* tmp = head;
while(tmp != nullptr){
if(tmp->data == value){
tmp->prev->next = tmp->next;
tmp->next->prev = tmp->prev;
delete tmp;
this->displayList();
return true;
}
else{
tmp = tmp->next;
}
}
Thanks in advance.
Aucun commentaire:
Enregistrer un commentaire