views:

176

answers:

2

I'm not sure I fully understand how to use the LinkedList class provided with SmallTalk Visual Works. I am able to create an instance of the class by simple doing:

myList := LinkedList new.

But how do I add a node. I tried creating an instance of Link class and setting a value but it doesn't seem to be working.

myLink := Link new.
myLink value: 3.

I am extremely new to smalltalk and any help would be greatly appreciated!

+4  A: 

As a newcomer rather learn how to use OrderedCollection instead. Then look at the methods of both classes and see the similarities and differences. You'll see that they are essentially the same, because the whole difference is in performance of inserting and removing elements in the middle of the collection. In OrderedCollection a whole collection is copied while in LinkedList just "pointers" are adapted to the inserted node.

In practice the LinkedList is rarely used, because the OrderedCollection is just good enough for most if not all needs.

Janko Mivšek
Indeed, the LinkedList is just an implementation detail for the Smalltalk Process class.
Paolo Bonzini
+2  A: 

The way you're supposed to use it is by subclassing Link, for example adding a value instance variable and two methods #value and #value:. But as Janko said, I wouldn't bother and just use an OrderedCollection.

Paolo Bonzini