LinkedList.st
changeset 2349 b68ab8aaabe1
parent 2146 27069b34fb5a
child 2350 20640ffa5141
equal deleted inserted replaced
2348:523e9d6e0049 2349:b68ab8aaabe1
   215     ^ aLink
   215     ^ aLink
   216 !
   216 !
   217 
   217 
   218 remove:aLink ifAbsent:exceptionBlock
   218 remove:aLink ifAbsent:exceptionBlock
   219     "remove the argument, aLink from the sequence; if absent,
   219     "remove the argument, aLink from the sequence; if absent,
   220      evaluate the exceptionBlock"
   220      evaluate the exceptionBlock.
       
   221      Actually this is really a removeIdentical (but for historic reasons ...)"
   221 
   222 
   222     |prevNode nextNode thisNode|
   223     |prevNode nextNode thisNode|
   223 
   224 
   224     thisNode := firstLink.
   225     thisNode := firstLink.
   225     [thisNode notNil] whileTrue:[
   226     [thisNode notNil] whileTrue:[
   226 	nextNode := thisNode nextLink.
   227         nextNode := thisNode nextLink.
   227 	(thisNode == aLink) ifTrue:[
   228         (thisNode == aLink) ifTrue:[
   228 	    prevNode isNil ifTrue:[
   229             prevNode isNil ifTrue:[
   229 		firstLink := thisNode nextLink
   230                 firstLink := thisNode nextLink
   230 	    ] ifFalse:[
   231             ] ifFalse:[
   231 		prevNode nextLink:(thisNode nextLink)
   232                 prevNode nextLink:(thisNode nextLink)
   232 	    ].
   233             ].
   233 	    (lastLink == thisNode) ifTrue:[
   234             (lastLink == thisNode) ifTrue:[
   234 		thisNode nextLink isNil ifTrue:[
   235                 thisNode nextLink isNil ifTrue:[
   235 		    lastLink := prevNode
   236                     lastLink := prevNode
   236 		] ifFalse:[
   237                 ] ifFalse:[
   237 		    lastLink := thisNode nextLink
   238                     lastLink := thisNode nextLink
   238 		]
   239                 ]
   239 	    ].
   240             ].
   240 	    numberOfNodes := numberOfNodes - 1.
   241             numberOfNodes := numberOfNodes - 1.
   241 	    thisNode nextLink:nil.
   242             thisNode nextLink:nil.
   242 	    ^ aLink
   243             ^ aLink
   243 	].
   244         ].
   244 	prevNode := thisNode.
   245         prevNode := thisNode.
   245 	thisNode := nextNode
   246         thisNode := nextNode
   246     ].
   247     ].
   247     ^ exceptionBlock value
   248     ^ exceptionBlock value
       
   249 
       
   250     "Modified: 1.2.1997 / 12:00:40 / cg"
   248 !
   251 !
   249 
   252 
   250 removeAll
   253 removeAll
   251     "remove all elements from the sequence. Returns the receiver."
   254     "remove all elements from the sequence. Returns the receiver."
   252 
   255 
   402 ! !
   405 ! !
   403 
   406 
   404 !LinkedList class methodsFor:'documentation'!
   407 !LinkedList class methodsFor:'documentation'!
   405 
   408 
   406 version
   409 version
   407     ^ '$Header: /cvs/stx/stx/libbasic/LinkedList.st,v 1.27 1997-01-11 12:16:08 cg Exp $'
   410     ^ '$Header: /cvs/stx/stx/libbasic/LinkedList.st,v 1.28 1997-02-01 11:00:51 cg Exp $'
   408 ! !
   411 ! !