213 lastLink |
213 lastLink |
214 "return last node in the list" |
214 "return last node in the list" |
215 |
215 |
216 lastLink isNil ifTrue:[self emptyCollectionError]. |
216 lastLink isNil ifTrue:[self emptyCollectionError]. |
217 ^ lastLink |
217 ^ lastLink |
|
218 ! |
|
219 |
|
220 linkAt:index |
|
221 "return the n'th element - use of this method should be avoided, |
|
222 since it is slow to walk through the list - think about using |
|
223 another collection if you need indexed access. |
|
224 Notice, that many methods in SeqColl are based on at:-access, |
|
225 so other inherited methods may be very slow (showing square runtime)." |
|
226 |
|
227 ^ self linkAt:index ifAbsent:[ self subscriptBoundsError:index] |
|
228 ! |
|
229 |
|
230 linkAt:index ifAbsent:exceptionBlock |
|
231 "return the n'th element - use of this method should be avoided, |
|
232 since it is slow to walk through the list - think about using |
|
233 another collection if you need indexed access. |
|
234 Notice, that many methods in SeqColl are based on at:-access, |
|
235 so other inherited methods may be very slow (showing square runtime)." |
|
236 |
|
237 |theLink |
|
238 runIndex "{Class: SmallInteger}"| |
|
239 |
|
240 theLink := firstLink. |
|
241 runIndex := 1. |
|
242 [runIndex == index] whileFalse:[ |
|
243 theLink isNil ifTrue:[^ exceptionBlock value]. |
|
244 theLink := theLink nextLink. |
|
245 runIndex := runIndex + 1. |
|
246 ]. |
|
247 ^ theLink |
218 ! ! |
248 ! ! |
219 |
249 |
220 !LinkedList methodsFor:'adding & removing'! |
250 !LinkedList methodsFor:'adding & removing'! |
221 |
251 |
222 add:aLinkOrAnyOtherObject |
252 add:aLinkOrAnyOtherObject |