adplus-dvertising
frame-decoration

Question

Select the function which performs insertion at the front end of the dequeue?
a)

public void function(Object item)
{
 Node temp = new Node(item,null);
 if(isEmpty())
 {
  temp.setNext(trail);
  head.setNext(temp);
 }
 else
 {
  Node cur = head.getNext();
  temp.setNext(cur);
  head.setNext(temp);
 }
 size++;
}

b)

public void function(Object item)
{
 Node temp = new Node(item,null);
 if(isEmpty())
 {
  temp.setNext(trail);
  head.setNext(trail);
 }
 else
 {
  Node cur = head.getNext();
  temp.setNext(cur);
  head.setNext(temp);
 }
 size++;
}

c)

public void function(Object item)
{
 Node temp = new Node(item,null);
 if(isEmpty())
 {
  Node cur = head.getNext();
  temp.setNext(cur);
  head.setNext(temp);
 }
 else
 {
  temp.setNext(trail);
  head.setNext(temp);
 }
 size++;
}

d) None of the mentioned

a.

a

b.

b

c.

c

d.

d

Answer: (a).a

Engage with the Community - Add Your Comment

Confused About the Answer? Ask for Details Here.

Know the Explanation? Add it Here.

Q. Select the function which performs insertion at the front end of the dequeue?