LinkedList.st
changeset 17272 46ac2aac776b
parent 17262 e7181a123eac
child 17273 4cb06da783b1
equal deleted inserted replaced
17271:47341245c458 17272:46ac2aac776b
   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
   476 ! !
   506 ! !
   477 
   507 
   478 !LinkedList class methodsFor:'documentation'!
   508 !LinkedList class methodsFor:'documentation'!
   479 
   509 
   480 version
   510 version
   481     ^ '$Header: /cvs/stx/stx/libbasic/LinkedList.st,v 1.46 2014-12-30 00:36:46 cg Exp $'
   511     ^ '$Header: /cvs/stx/stx/libbasic/LinkedList.st,v 1.47 2014-12-30 12:50:31 cg Exp $'
   482 !
   512 !
   483 
   513 
   484 version_CVS
   514 version_CVS
   485     ^ '$Header: /cvs/stx/stx/libbasic/LinkedList.st,v 1.46 2014-12-30 00:36:46 cg Exp $'
   515     ^ '$Header: /cvs/stx/stx/libbasic/LinkedList.st,v 1.47 2014-12-30 12:50:31 cg Exp $'
   486 ! !
   516 ! !
   487 
   517