Linked Data Structures Flashcards
What is a Linked List?
A linked list consists of a single chain of nodes each connected to the next by a link.
What is the first node in a linked list
The first node, or start node in a linked list is called the head node.
The entire linked list can be traversed by starting at the head node.
Does a linked list object contain all the nodes in the linked list directly?
It does not. Rather, it uses the instance variable head to locate the head node of the list. Therefore, once the head node can be reached, then every other node in the list can be reached.
How is an empty linked list indicated?
- The head instance variable contains a reference to the first node in the linked list. If the list is empty, this instance variable is set to null.
- The linked list constructor sets the head instance variable to null. This indicates that the newly created linked list is empty.
How do you indicate the end of a linked list?
The last node in a linked list should have its link instance variable set to null. That way the code can test whether or not a node is the last node.
How do you traverse a linked list?
If a linked list already contains nodes, it can be traversed as follows:
- set a local variable equal to the value stored by the head node (its reference)
- This will provide the location of the first node.
- After accessing the first node, the accessor method for the link instance variable will provide the location of the next node.
- Repeat this until the location of the next node is equal to null.
What is a stack data structure?
A stack data structure is not necessarily a linked data structure, but can be implemented as one. A stack removes items in the reverse order of which they were inserted. (LIFO: Last in First Out)