------- <a target="blank">android培训</a>、<a target="blank">java培训</a>、期待与您交流! ----------
class Node{
private string name;
private Node next;
public Node(string name){this.name=name;}
public void setNext(Node next){this.next=next}
public Node getNext(){return this.next;}
public String getName(){return this.name;}
}
public class LinkDemo01{
public static void main(string args[]){
Node root=new Node("root point");
Node na=new Node("yi point");
Node nb=new Node("er point");
Node bc=new Node("san point");
root.setNext(na);
na.setNext(nb);
nb.setNext(nc);
print(root);
}
public static void print(Node node){
if(node != null)
System.out.println(node.getName()+"->");\
if(node.getNext != null)
print(node.getNext());
}
}
一个简单的单向链表就实现了
|
|