Question: Write a method deleteBack that deletes the last value (the value at the back of the list) and returns the deleted value. If the list

Write a method deleteBack that deletes the last value (the value at the back of the list) and returns the deleted value. If the list is empty, your method should throw a NoSuchElementException.

ListNode below:

private static class ListNode { public E data; // data stored in this node public ListNode next; // link to next node in the list public ListNode prev; // link to previous node in the list // post: constructs a node with given data and null links public ListNode(E data) { this(data, null, null); } // post: constructs a node with given data and given links public ListNode(E data, ListNode next, ListNode prev) { this.data = data; this.next = next; this.prev = prev; } }

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!