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

2. Removing nodes storing a given value from a linked list. You are given a link

ID: 3639256 • Letter: 2

Question

2. Removing nodes storing a given value from a linked list. You are given a linked list L storing integers and you are asked to remove all nodes storing a given value A. Hint: the algorithm traverses the linked list looking for nodes that store A. When a node is removed, the links need to be repaired, opposite to what we did in class for insertion.
a. Give a brief step by step description of the algorithm.
Look at the list
Match with the element to be removed to the current element in the list
When it finds the match in the list, it removes the element and adjusts the pointer of the previous element to the next element in the list
b. Give a pseudocode description of the algorithm.
c. Trace the algorithm for L = {1, 2, 3, 2} and A = 2.
d. If the number of nodes in the list is n, what is the algorithm running time? Explain.

If you know any of these a or b or c or d. Please help

Explanation / Answer

You have already given a pseudo-code so I will just write the code.
Its pretty easy and self explanatory.

Declaration of a node

 


the search function:

int getElementpos( olist L , char A ) {

int pos=0;

if (L->element == A) return pos;

else {

L= L->next;

++pos;

}

the delete function :

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