Java Reference
In-Depth Information
1
/**
2
* Construct the list
3
*/
4
public LinkedList( )
5
{
6
header = new ListNode<AnyType>( null );
7
}
8
9
/**
10
* Test if the list is logically empty.
11
* @return true if empty, false otherwise.
12
*/
13
public boolean isEmpty( )
14
{
15
return header.next == null;
16
}
17
18
/**
19
* Make the list logically empty.
20
*/
21
public void makeEmpty( )
22
{
23
header.next = null;
24
}
25
26
/**
27
* Return an iterator representing the header node.
28
*/
29
public LinkedListIterator<AnyType> zeroth( )
30
{
31
return new LinkedListIterator<AnyType>( header );
32
}
33
34
/**
35
* Return an iterator representing the first node in the list.
36
* This operation is valid for empty lists.
37
*/
38
public LinkedListIterator<AnyType> first( )
39
{
40
return new LinkedListIterator<AnyType>( header.next );
41
}
figure 17.9
Some
LinkedList
class one-liners
Let us revisit the issue of whether all three classes are necessary. For
instance, couldn't we just have the
LinkedList
class maintain a notion of a
current position? Although this option is feasible and works for many
applications, using a separate iterator class expresses the abstraction that the
Search WWH ::
Custom Search