简单链表练习
class Node{
private String data;
private Node next;
public Node(String data) {
this.data=data;
}
public void setNext(Node next) {
this.next=next;
}
public Node getNext() {
return this.next;
}
public String getData() {
return this.data;
}
}
public class TestDemo{
public static void main(String args[]) {
Node root =new Node(“起始节点”);
Node next1 =new Node(“节点1”);
Node next2 =new Node(“节点2”);
root.setNext(next1);
next1.setNext(next2);
Node currentNode =root;
while(currentNode!=null) {
System.out.println(currentNode.getData());
currentNode=currentNode.getNext();
}
}
}