This is the smalltalk code I wrote to deep copy two linkedlist object.But when I do this Small talk interpreter raises an error stating that:Unhandled Exception: Message not Understood: nextlink.
list1 add:2.
list2 :=list1 dcopy.
list1 ==list2.
Kindly tell me what is the problem with my code.
This is VisualWorks. LinkedLists are collections used for internal system use and aren't intended for general use. The items added into LinkedLists must subclass from Link (or implement nextLink and nextLink:). You can't add a SmallInteger into a linked list. You can do this:
LinkedList new
add: (LinkValue value: 5);
add: (LinkValue value: 7)
We don't generally use linked lists in Smalltalk. We normally use OrderedCollection instead. If you really need a linked list, add elements which are subclasses of Link.