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. A sensible implementation of any type of data structure must allow it to be empty.
Here is a tester method for the LinkedList class that creates an empty list:
// LinkedListTester.java
//
public class LinkedListTester
{
public static void main( String[] args )
{
// create an empty linked list
LinkedList list = new LinkedList();
}
}
Running the program prints nothing, but behind the scenes an empty linked list is constructed (and then becomes garbage when the program ends.)
C:\JavaSource> javac Node.java LinkedList.java LinkedListTester.java C:\JavaSource> java LinkedListTester C:\JavaSource>
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, otherwise return false
}