Java Reference
In-Depth Information
115
116 /**
117
Adds an element before the iterator position
118
and moves the iterator past the inserted element.
119 @param element
the element to add
120 */
121
public void
add(Object element)
122 {
123
if
(position ==
null
)
124 {
125 addFirst(element);
126 position = first;
127 }
128
else
129 {
130 Node newNode =
new
Node();
131 newNode.data = element;
132 newNode.next = position.next;
133 position.next = newNode;
134 position = newNode;
135 }
136 previous = position;
137 }
138
139 /**
140
Removes the last traversed element. This method may
141
only be called after a call to the
next()
method.
142 */
143
public void
remove()
144 {
145
if
(previous == position)
146
throw new
IllegalStateException();
147
148
if
(position == first)
149 {
150 removeFirst();
151 }
152
else
153 {
154 previous.next = position.next;
155 }
156 position = previous;
679
680