Question: Question 5: True or False: the public void add(E e)method always adds the new item at the beginning of the linked list. Question 6: True

Question 5: True or False: the public void add(E e)method always adds the new item at the beginning of the linked list. Question 6: True or False: the public void add(E e) method will take longer to execute the more items are in the linked list.

Question 7: The unlink method contains the following lines of code: if (prev == null) { first = next; } else { prev.next = next; x.prev = null; } If the method is called with the first Node in the list as the parameter value, which of these will be executed: the if clause or the else clause?

Question 8: True or false: in general, the contains method takes longer to execute the more items there are in the linked list.

***public void add (E e) method ****(question 5 and 6)

public void add(E e) {

checkForComodification();

lastReturned = null;

if (next == null)

linkLast(e);

else

linkBefore(e, next);

nextIndex++;

expectedModCount++;

}

****end of public add method****

****unlink method**** question 7

/**

* Unlinks non-null node x.

*/

E unlink(Node x) {

// assert x != null;

final E element = x.item;

final Node next = x.next;

final Node prev = x.prev;

if (prev == null) {

first = next;

} else {

prev.next = next;

x.prev = null;

}

if (next == null) {

last = prev;

} else {

next.prev = prev;

x.next = null;

}

x.item = null;

size--;

modCount++;

return element;

}

***end of unlink methood*****

***contains method*******question 8

/**

* Returns {@code true} if this list cs the specified element.

* More formally, returns {@code true} if and only if this list contains

* at least one element {@code e} such that

* (o==null ? e==null : o.equals(e)).

* @param o element whose presence in this list is to be tested

* @return {@code true} if this list contains the specified element

*/

public boolean contains(Object o) {

return indexOf(o) != -1;

}

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!