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.
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.