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

DQuestion 1 1 pts Consider the DoublyLinkedList implementation from class: publi

ID: 3600829 • Letter: D

Question

DQuestion 1 1 pts Consider the DoublyLinkedList implementation from class: public class DoublyLinkedList private Node head, tail; private static class Node public Node prev, next public String data public Node(Node prev, String data, N ode next) this . prev this.next this.data prev; next ; data public DoublyLinkedList) head = tail null; *Add data to the end (tail) of the Dou blyLinkedList public void add(String data) f if (tail =null) { head : tail new Node( null, data, null): else ( assert ltail.next null); tail.next new Nodel tail, data, nu Ll): tail- tail.next + Retrieve an elenent from the middle o * eparan i Zero-based index of the elen * @return The elenent (TBD: what to do f the list ent to retrieve if i is invalid) public String getlint 1) Node current-head: for (int 1 i;) / Count our way up to the desired element current current.next ; return current data; What would happen if we ran the following code? You may want to try it in Eclipse.

Explanation / Answer

Answer:

a will be printed

Explanation:

list will have a as data in the head.

When we call list.get(-1)

Node current=head will give us current value in the head of the Node.

Then in the loop j value=0 which is greater than -1,condition fails and loops come out

then current.data will have a data and it returns a value