Yes. In this case the headPtr
is null
.
This is how LinkedList
looks just after construction.
A linked list without any nodes is called empty.
However, the LinkedList
object still exists.
Here is a tester method for the LinkedList
class that creates an empty list:
public class LinkedListTester { public static void main( String[] args ) { // create an empty linked list LinkedList list = new LinkedList(); } }
After an empty list has been created, nodes can be linked into a chain using list.insertFirst()
.
Complete the isEmpty()
method of LinkedList
.
// Determine if the List is empty public boolean isEmpty() { // return true for an empty list }