12.5k views
1 vote
Deleting anitem from a linked list is best when performed using two pointersso that the deleted item is freed from memory.

a.True
b. False

User Ivankeller
by
6.5k points

1 Answer

2 votes

Answer:

a.True.

Step-by-step explanation:

To delete a node from linked list it is best to do it by using two pointers suppose say prev and curr. Iterating over the linked list while curr is not NULL and updating prev also.On finding the node to be deleted we will set the prev so that it points to the next of curr and after removing the link we will free curr from memory.

line of code for deleting a node in c++:-

prev->next=curr->next;

delete curr; or free(curr);

User Alterscape
by
5.3k points