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

ODPmers, Alice and Bob, are consdering iopiemesting terms of linked-lists. They

ID: 3591349 • Letter: O

Question

ODPmers, Alice and Bob, are consdering iopiemesting terms of linked-lists. They start from the same code public class QueucE PrSvate Node in PrAvace int size public void ofter(E item) pending. . There are two possible interpretations for in and out as depicted below Alice in out Bob out in The field in indicates where incoming items are placed and out references the next item that is to be removed from the queue. 1. Write the code for offer for both solutions. Note: you may not add new data fields to the class Queue. 2. Indicate which of the proposals is best, that of Alice or that of Bob. Justify your answer by supplying a complexity argument.

Explanation / Answer

a>Alice:

public void offer (E item){

private node<E> current;

private node<E> previous;

current=in;

private node<E> temp ;

temp.item =E;

temp.next=in;

current=temp;

while(current.next != Null)

{

if(current.next != out)
{
previous=current;
current=current.next;
}
if (current.next ==out)
{
break;
}
}
previous.next=current.next;
current.next=null;

}


bob:

public void offer (E item){

private node<E> current;


current=out;

private node<E> temp ;
current.next=null;

while(current.next != Null)

{

if(current.next != in)
{
current=current.next;
}
if (current.next ==in)
{
break;
}
}

temp.item=E;

temp.next=current.next;
current.next=temp;


}

b>For the below two scenarios both will run at same complexity.because both have only single loop.that povide both the case time complexity of O(n).