Unit 3 Chapter 5 Linked Lists Terms & Concepts Flashcards
Each Link object contains references to:
to a data item, to next link in the list. A field in the LinkList class refers to the first link.
how is linked-list self-referential?
it contains a field - called next - of the same type object as itself
in an array each item occupies a particular position which can be accessed using an index number, what is the process for linked lists?
in a list, the only wat to find a particular element is to follow along the chain of elements.
where are new links added in a linked list?
at the beginning of the list.
how are links removed in a linked list?
the reference to the preceding link is changed to point to the following link.
in the link constructor, what is next automatically set to?
null
what is the process for inserting a new link using the insertFirst method of a linked list?
set the next field in the newly created link to point to the old first link, and then change first so it points to the newly created link.
what is the process for deleting a link using the deleteFirst method of a linked list?
it disconnects the first link by rerouting first to point to the second link. DeleteFirst assumes the list is not empty, verify using isEmpty.
what is the process for displayList method of a linked list?
starts at first and follow chain of references from link to link. The variable current refers to each link in turn.
what is the process for finding a link using the delete( ) method of a linked list?
searches for link to be deleted, maintains a reference to the current link and and previous link, deletes the current link, connects the preceding link to the following link. At each cycle through the while loop, just before current is set to current.next, previous is set to current.
Double-ended list definition
a double-ended list is similar to an ordinary linked list, but it has an additional reference to the last link as well as the first.
What is the purpose of the additional reference to the last link in a double=ended list?
The reference to the last link permits you to insert a new link directly at the end of the list as well as the beginning.
what is the process for the method insertLast in a double-ended list?
modify last.next to point to the new link and then change last to point to the new link.
what consideration must be made in the special case when the double-ended list is empty prior to insertion?
if isEmpty is true, then insertFirst must set last to the new link and insertLast must set first to the new link.
what is linked list efficiency for insertion, deletion and deleting inserting next to a specific item
insert first and delete first takes O(1) time. requires O(N) comparisons for insert and delete of specific item.