Decoding LinkedList Question 1: The LinkedList class uses another class called N
ID: 3859437 • Letter: D
Question
Decoding LinkedList
Question 1: The LinkedList class uses another class called Node (which is defined inside LinkedList.java). What are the fields in the Node class?
Question 2: The Node class uses generics. Why?
Question 3:The linkFirst method contains the following lines of code:
if (f == null)
last = newNode;
else
f.prev = newNode;
What is the value of the linked list’s size attribute at this point in the code if f ==null is true?
Question 4: True or False: the removeLast method will take longer to execute the more items are in the linked list.
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 containsmethod takes longer to execute the more items there are in the linked list.
Question 9: The indexOf method always returns -1 if it is passed a null argument?
Explanation / Answer
1. The LinkedList class uses another class called Node (which is defined inside LinkedList.java). What are the fields in the Node class?
Fields are data and next
Question 2: The Node class uses generics. Why?
So that it can contain data of any type..String, integer, Char, double etc
3. What is the value of the linked list’s size attribute at this point in the code if f ==null is true?
Size is zero when f==null
Question 4: True or False: the removeLast method will take longer to execute the more items are in the linked list.
True: because it has o move to the end of the list and then remove , so as the list grows larger it takes more time to reach the end;
Question 5: True or False: the public void add(E e)method always adds the new item at the beginning of the linked list.
True : It always add at the front
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.
False: As its adds at the beginning it wont take much time
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?
if case will be execute because, It is the first node and its prev will be null.
Question 8: True or false: in general, the contains method takes longer to execute the more items there are in the linked list.
True: Because it scans the list and checks every element, If the list grows bigger more elements needs to be checked, So Yeah it takes longer to execute the more items there are in the linked list.
Question 9: The indexOf method always returns -1 if it is passed a null argument?
No, It returns false when you pass a null argument
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.