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

I will 100% rate 2. (40 pts) Implement the methods specified given the following

ID: 3717029 • Letter: I

Question

I will 100% rate

2. (40 pts) Implement the methods specified given the following class. Assume that all methods are implemented-except for those which you are asked to implement-and work as their names imply (ask if you are unsure). You must implement the requested functionality fully within the assigned method; you may not alter the class declaration. An empty list is initialized with a null head and tail; otherwise, head addresses the first node in the list, and tail addresses the last class exam_list class exam_list_node £ public: const char *data; exam_list_node *next; exam_list_node previous; inline exam_list_node (const char *d, exam_list_node *n, exam_list_node *p): data (d), next (n), previous (p) if (next) ( next->previous = this; if (previous) previous->next = this ; private: exam_list_node head; exam_list_node *tail; public: exam_list) : head(0), tail(0) C) exam_1list) clear; ) void clear ; void insert_tail(const char *d) exam_list & operator- (const exam list ⪙); friend ostream &operator;

Explanation / Answer

void clear()

{

    // point trav to head of the list

    exam_list_node *trav = head;

   

    // point to the previous node

    exam_list_node *pre = NULL;

   

    // loop untill list ends

    while( trav )

    {

        pre = trav;

       

        // move to the next node

        trav = trav->next;

       

        // delete the previous node

        delete pre;

    }

   

    // make the pointers NULL

    this->head = NULL;

    this->tail = NULL;

}

// assuming the insert_tail() function works

exam_list &operator=( const exam_list &el )

{

    // clear he current list

    this->clear();

   

    // point trav to head of the el list

    exam_list_node *trav = el.head;

   

    // loop untill el list ends

    while( trav )

    {

        // insert a new node at the tail of current list

        this->insert_tail( trav->data );

       

        // move to next node

        trav = trav->next;

    }

   

    return *this;

}

// if there is a problem with the solution, please leave a comment and I will definitely resolve your problem :)