2009/1/13 Hilaire Fernandes <[email protected]>: > 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 > [email protected] > http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project > -- Best regards, Igor Stasenko AKA sig. _______________________________________________ Pharo-project mailing list [email protected] http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
