Question
Hello!, im trying to implement a removeAfter method in Java and this is my current implementation I am only failing 1 test case but I
Hello!, im trying to implement a removeAfter method in Java and this is my current implementation I am only failing 1 test case but I don't know where my logic is failing. any help would be great. Implementation: public
Instructions:
20 pts) Head over to RemoveAfterProblem.java after finishing exercise 3. The instructions for this exercise are as follows:
Implement a method called removeAfter() that removes from the List all elements, if any, that are immediately after one occurrence of a given element and which are not equal to the given element.
The method receives as a parameter a Node that represents the head of a linked list, as well as a target which represents the element we are searching for such that we can remove the subsequent node immediately after that one.
Note: If the subsequent node contains the target element it will not be removed, we only remove nodes whose value is different from target.
Example, assume that a call to removeAfter(head, 5) is made.
If head is referencing the List {4, 5, 5, 6, 8, 5, 9, 5}, then the List remaining would be {4, 5, 5, 8, 5, 5}., and the method would return value 2 (number of removals).
If head is referencing the List {4, 3, 6, 7, 8}, then the List is not altered because it has no occurrence of 5, and the method would return 0.
Your solution must be as efficient as possible and must properly apply the clear() method (of class Node) to each deleted node.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started