I have a problem understanding the exercises. I have to develop a linear linked list. But I do not need to distinguish between the list and node.
The Node constructor should create a Node and add it to the list, which is passed as a parameter.
I usually looked at the list and added Node at the end. Here is my code.
class Node{
Object data;
Node link;
public Node(Object pData, Node pLink){
this.data = pData;
this.link = pLink;
}
public String toString(){
if(this.link != null){
return this.data.toString() + this.link.toString();
}else{
return this.data.toString() ;
}
}
public void inc(){
this.data = new Integer((Integer)this.data + 1);
}
}
Perhaps I just learned a lot today, and my brain cannot accept more information: D, please help!
source
share