Java Reference
In-Depth Information
47
public void
addFirst(E element)
48 {
49 Node newNode =
new
Node();
50 newNode.data = element;
51 newNode.next = first;
52 first = newNode;
53 }
54
55 /**
56
Returns an iterator for iterating
through this list.
57 @return
an iterator for iterating
through this list
58 */
59
public
ListIterator<E> listIterator()
60 {
61
return new
LinkedListIterator();
62 }
63
64
private
Node first;
65
66
private class
Node
67 {
68
public
E data;
69
public
Node next;
70 }
71
72
private class
LinkedListIterator
implements
ListIterator<E>
73 {
74 /**
75
Constructs an iterator that points
to the front
76
of the linked list.
77 */
78
public
LinkedListIterator()
79 {
80 position =
null
;
81 previous =
null
;
82 }
83
84 /**
771
772