Question: JAVA - If incomplete what is incomplete about it? /** * deleteMax removes and returns the maximum number in the linked list you * can

JAVA - If incomplete what is incomplete about it?

/** * deleteMax removes and returns the maximum number in the linked list you * can assume there are no duplicates in the * * Examples: LinkedList : 4 --> null ==> return 4 and the resulting linked * list is null LinkedList : 2 --> 3 --> null ==> return 3 and resulting * linked list is 2 --> null LinkedList : 1 --> -3 --> null ==> return 1 and * resulting linked list is -3 --> null */

code I have:

public int deleteMax() { int newMax = first.data; Node maxNode = first; Node prevNode = first; Node prev = null; if ( first == null){ return 0; } for (Node n = first; n != null; n = n.next) { if (n.next.data > newMax) { newMax = n.data; maxNode = n; prevNode = prev;

} prev = n; }

prevNode.next = maxNode.next;

return newMax; // TODO }

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!