Question: I'm trying to figure out how to do some recursive linked list methods (in java), but I'm having some trouble with them. The methods are

I'm trying to figure out how to do some recursive linked list methods (in java), but I'm having some trouble with them. The methods are remove (E element) and max(). Both must be recursive. Here's my code so far:

public void remove(E element){ head=remove(head,element); } public Node remove(Node node, E value){ if(node==null){return null;} if(node.data.equals(value)){System.out.println(node.next); return node.next;} node.next=remove(node.next,value); return node; }

public E max(){ return max(head); } public E max (Node node){ Node max=null; if (node.next ==null){return node.data; }else{ if(((node.next.data).comparedTo(node.data))>0){ max= node.next; max(node.next); } return max.data; } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!