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

Write the code for a new LinkedList method that removed the node AFTER the one s

ID: 3545233 • Letter: W

Question

                        Write the code for a new LinkedList method that removed the node AFTER the one specified by the para                     

                                                                  meter. The signature of this new method is provided below.                         

                            
                        

                        

                            private AnyType removeAfter ( Node<AnyType> p) {                         

                        

                            
                        

                                                     }

Explanation / Answer

private AnyType removeAfter ( Node<AnyType> p) {

AnyType temp = p;

temp.nextLink=null;

return p;

}



here what we have done is after p all node are deleted but node p is still present if u want to get the first node return

then u have to send it as an arguement in function then only we can do it as linklist is one way rood it look like



private AnyType removeAfter ( Node<AnyType> p ,Node<AnyType> first) {

AnyType temp = p;

temp = temp.nextLink;

temp.nextLink=null;

return first;

}



or i can think as first node as global variable node can be used by every function


private AnyType removeAfter ( Node<AnyType> p ) {

AnyType temp = first;
while(temp==p)
temp = temp.nextLink;


temp.nextLink=null;
return first;

}