Когда я удаляю узел из двусвязного списка, он не удаляется, вместо этого он показывает 0 в этом месте узла.
, когда я вставляю узлы в начале для ex = 10 20 30 40 и выведите его = 40,30,20,10
, но когда я удаляю для ex 30, а затем я печатаю список, он печатает = 40 0 20 10
почему отображается этот 0?
node* delete_node(node* head, int value)
{
node * curr = head;
// Reaching to node of the given value.
while(curr -> key != value)
{
// If the node to be deleted not found.
if(curr -> next == NULL)
{
cout<<"THE NODE TO BE DELETED NOE FOUND";
return head;
}
curr = curr -> next;
}
// If the node to be deleted is the last node.
if(curr -> next == NULL)
{
curr -> prev -> next = NULL;
return head;
}
// If the node to be deleted is a normal node in between of the list.
(curr -> next)-> prev = curr -> prev;
(curr -> prev)-> next = curr -> next;
delete curr;
return head;
}