[Pharo-project] Help clarify

Igor Stasenko siguctua at gmail.com
Tue Jan 13 06:46:31 EST 2009


2009/1/13 Hilaire Fernandes <hilaire at ofset.org>:
> I need to write a DoubleLinkedList, checking for LinkedList I saw
>
> add: link after: otherLink
>
>        "Add otherLink  after link in the list. Answer aLink."
>
>        | savedLink |
>        lastLink == otherLink ifTrue: [^ self addLast: link].
>        savedLink := otherLink nextLink.
>        otherLink nextLink: link.
>        link nextLink:  savedLink.
>        ^link.
>
> Why is savedLink needed ?
>
> Why not:
>        lastLink == otherLink ifTrue: [^ self addLast: link].
>        link nextLink:  otherLink nextLink.
>        otherLink nextLink: link.
>        ^link.
>
> Are there any hidden reason I don't see?
>

isn't a DoubleLinkedList means that there should be not only next, but
prev as well?
then, if nextLink: implemented as following (i don't have sources):

nextLink: aLink
  next := aLink.
  aLink prev: self

then you should use  savedLink to avoid losing a correct prev link.


> --
> http://blog.ofset.org/hilaire
>
> _______________________________________________
> Pharo-project mailing list
> Pharo-project at lists.gforge.inria.fr
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>



-- 
Best regards,
Igor Stasenko AKA sig.




More information about the Pharo-dev mailing list