An empty ordered list looks the same as an empty unordered list.
This is how an OrderedLinkedList
looks just after construction.
A sensible implementation of any type of data structure must allow for the
situation where the data structure holds no data.
Recall the software engineering principle: test early, test often. Here is a program that tests what we have so far:
public class OrderedLinkedListTester { public static void main( String[] args ) { // create an empty ordered linked list OrderedLinkedList list = new OrderedLinkedList(); if ( list.isEmpty() ) System.out.println("List created successfully!"); else System.out.println("Something is wrong."); } }
After an empty list has been created, nodes can be linked into the chain using list.insertInOrder()
(which needs to be written).
(Thought Question: ) Would the methods insertFirst()
and insertLast()
from the LinkedList
class
of the previous chapter be useful?