黑马程序员技术交流社区

标题: note节点 [打印本页]

作者: 434510655    时间: 2013-2-22 12:05
标题: note节点
------- <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());
}
}
一个简单的单向链表就实现了






欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2