Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Within the solution box, implement the following: The Train class\'s destructor,

ID: 3801190 • Letter: W

Question

Within the solution box, implement the following: The Train class's destructor, the destructor should properly destroy the linked list of train cars. Assume the other functions are implemented correctly. The Train class's function: remove First Car of Type. This function removes the first car from the list that has a string name that matches the provided string. Do not use any other Train class Your solution for the above functions should go in this box, which should be considered part of train.

Explanation / Answer

2 A

// constructor
Train()
{
head = NULL;
}

//Destructor
~Train(void)
{
struct Node* temp;
while (head != NULL)
{
temp = head->next;
delete head;
head= temp;
}
}

2B.

void removeFirstCarofType(string str)
{
struct Node* temp=head,*q;
while(strcmp(temp->name,str)!=0)
{
q=temp;
temp=temp->next;
}
if(strcmp(temp->name,str)==0)
{
q->next=temp->next;
delete temp;
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote