Which of the following is the correct code for the destructor for a class that h
ID: 3858973 • Letter: W
Question
Which of the following is the correct code for the destructor for a class that holds information in a linked list? node* rmptr: while(head != NULL){ rmptr = head: head - head- > link(): delete rmptr: } node*rmptr: while(head != NULL){ rmptr = head: head = head- > link(): delete head: } delete [] head: node* rmptr: while(head!- NULL){ head = rmptr: head = head- > link(): delete rmptr: } The distinction between a set and a multiset is that a multiset allows duplicates. a multiset is in the library a multiset is ordered. a multiset has an iterator.Explanation / Answer
The correct answer is:
node *rmptr;
while(head!=NULL)
{
rmptr = head;
head = head->link();
delete rmptr;
}
Because rmptr points to the courrent node while head preserves the address of next node. Hence whole list can be destroyed successfully.