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

Please assume that these are already within a class: static class Node { public

ID: 3592775 • Letter: P

Question

Please assume that these are already within a class:

   static class Node {

       public Node (double item, Node next) { this.item = item; this.next = next; }

       public double item;

       public Node next;

   }

   Node first;

   // a function to delete the second node if it exists, if not, the list is unchanged

   // [0,1,2,8,9].deleteSecondIfPossible() --> [0,2,8,9]

   // [0,9].deleteSecondIfPossible() --> [0]

   // [].deleteSecondIfPossible() --> []

   public void deleteSecondIfPossible () {

       // TODO 5: fix this

   }

Thanks!!

Explanation / Answer

public void deleteSecondIfPossible () {

if (first != null){

if(first.next != null){

first.next = first.next.next;

}

}

}