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

C++ *20.1 (Implement remove(T element)) The implementation of remove(T element)

ID: 3601217 • Letter: C

Question

C++ *20.1 (Implement remove(T element)) The implementation of remove(T element) is omitted in Listing 20.2, LinkedList.h. Implement it.

For input use this sentence, which you may code as a constant string: "DURING the whole of a dull, dark, and soundless day in the autumn of the year, when the clouds hung oppressively low in the heavens, I had been passing alone, on horseback, through a singularly dreary tract of country; and at length found myself, as the shades of the evening drew on, within view of the melancholy House of Usher."

Your test case should show the string after being loaded into a linked list and then again after the word “of” has been removed.

Explanation / Answer

the requested code is as follows :

---------------------------------------------------------------------------------------------------------------

void remove( T element)

{

    Node<T> * temp,*prev;

    temp = head;         // temp pointer pointing to head pointer

    prev = temp;

    while( temp != NULL)

     {

            if( temp -> getValue() == element ){

                                 prev -> next = temp -> next;      // updating the link of prev to next of temp

                                 delete temp; // freeing the pointer

            }

            else {

                          prev = temp; // moving both one step further

                          temp = temp -> next;  

            }

     }
}

---------------------------------------------------------------------------------------------------

/* hope this helps */

/* if any queries please comment */

/* thank you */