package test;
//目标:使用内部类创建结点并遍历
class LinkNode{
private class Node{
private String data;
private Node next;
public Node(String data){
this.data=data;
}
public String getData(){
return this.data;
}
public Node getNextNode(){
return this.next;
}
public void addNode(Node newNode){
if(this.nextnull){
this.next=newNode;
}
else{
this.next.addNode(newNode);
}
}
}
private Node root;
public void addNode(String data){
if(datanull) return;
Node newNode=new Node(data);
if(this.root==null){
this.root=newNode;
}
else{
this.root.addNode(newNode);
}
}
public void print(){
Node node=root;
while(node!=null){
System.out.println(node.getData());
node=node.getNextNode();
}
}
}
public class T_7 {
public static void main(String[] args) {
// TODO Auto-generated method stub
LinkNode linkNode=new LinkNode();
linkNode.addNode("head");
linkNode.addNode("1111");
linkNode.addNode("2222");
linkNode.addNode("1111");
linkNode.addNode("2222");
linkNode.print();
}
}