Question: It looks like the current implementation may not handle the case where the first player ( head of the list ) needs to be replaced
It looks like the current implementation may not handle the case where the first player head of the list needs to be replaced properly, especially when inserting p before p
test case
public void testA
c concealHigherScoregetInstance;
p new Playerjoe Position.Quarterback;
p new Playerjoe Position.DefensiveLine;
p new Playerjoe Position.Kicker;
paddInPriorityp c;
paddInPriorityp c;
testPlayersp p p;
My method
public void addInPriorityPlayer p Comparator priority
TODO: Implement this method. No loops, only recursion.
NB: While Team happens to call this method only on the head of the list,
we can't assume all classes that utilize Player will do so That is why
we must consider all scenarios, including those where this method is
called on a player in the middle or end of the list.
int a priority.comparep this;
Left of this and Immediate left is null
add p left with mumtiples players
ifa
ifthisprev null
pnext this;
this.prev p;
else
this.prev.addInPriorityp priority;
right of this, and immediate right null
add p right with multiples players
else ifa
ifthisnext null
this.next p;
pprev this;
else
this.next.addInPriorityp priority;
equal to this
else
ifthisnext null
this.next.prev p;
pnext this.next;
this.next p;
pprev this;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
