Questions Chapter 5 Flashcards
Which of the following is NOT true? A reference to a class object:
a. can be used to access public methods in the object
b. has a size dependant on class.
c. has the data type of the class
d. does not hold the object itself.
b. has a size dependant on its class.
Access to the links in a linked list is usually through the _______ link.
first
When you create a reference to a link in a linked list, it:
a. must refer to the first link
b. must refer to the link pointed to by current
c. must refer to the link pointed to by next.
d. can refer to any link you want
d. can refer to any link you want.
How many references must you change to insert a link in the middle of a singly linked list?
2.
How many references must you change to insert a link at the end of a singly linked list?
1
In the insertFirst( ) method in the LinkList.java program (Listing 5.1), the statement newLink.next = first; means that:
a. the next new link to be inserted will refer to first
b. first will refer to the new link
c. the “next” field fo the new link will refer to the old first link
d. newLink.next will refer to the new first link in the list
c. the “next” field of the new link will refer to the old first link.
Assuming current points to the next-to-last link in a singly linked list, what statement will delete the last link from the list?
current.next = null;
When all references to a link are changed to refer to something else, what happens to the link?
garbage collection
A double-ended list:
a. can be accessed from either end
b. is a different name for a doubly linked list
c. has pointers running both forward and backward between links
d. has its first link connected to its last link
a. can be accessed from either end.
A special case often occurs for insertion and deletion routines when a list is ________.
empty
Assuming a copy takes longer than a comparison, is it faster to delete an item with a certain key from a linked list or from an unsorted array?
linked list
How many times would you need to traverse a singly linked list to delete the item with the largest key?
1
Of the lists: simple linked list, double-ended list, sorted list, doubly linked list, which one would be best for implementing a queue?
double-ended
Which of the following is NOT true? Iterators would be useful if you wanted to:
a. do an insertion sort on a linked list
b. insert a new link at the beginning of a list
c. swap two links at arbitrary locations
d. delete all links with a certain key value
b. insert a new link at the beginning of a list
Which do you think would be a better choice to implement a stack: a singly linked list or an array?
the list. The both do push( ) and pop ( ) in O(1) time, but the list uses memory more efficiently .