Java Reference
In-Depth Information
120 // determine whether list is empty
121
122 {
123 return firstNode == null ; // return true if list is empty
124 }
125
126 // output list contents
127
128 {
129 if (isEmpty())
130 {
131 System.out.printf( "Empty %s%n" , name);
132 return ;
133 }
134
135 System.out.printf( "The %s is: " , name);
136 ListNode<T> current = firstNode;
137
138 // while not at end of list, output current node's data
139 while (current != null )
140 {
141 System.out.printf( "%s " , current.data);
142 current = current.nextNode;
143 }
144
145 System.out.println();
146 }
147 } // end class List<T>
public boolean isEmpty()
public void print()
Fig. 21.3 | ListNode and List class declarations. (Part 4 of 4.)
1
// Fig. 21.4: EmptyListException.java
2
// Class EmptyListException declaration.
3
package com.deitel.datastructures;
4
5
public class EmptyListException extends RuntimeException
6
{
7
// constructor
8
public EmptyListException()
9
{
10
this ( "List" ); // call other EmptyListException constructor
11
}
12
13
// constructor
14
public EmptyListException(String name)
15
{
16
super (name + " is empty" ); // call superclass constructor
17
}
18
} // end class EmptyListException
Fig. 21.4 | Class EmptyListException declaration.
Search WWH ::




Custom Search