package moumoumou.xxx
class Node {
public int val;
public Node next; // 对象为Node类的next 变量
public Node (int val){
this.val = val; //Java的语法,this表示Node对象里的(属性等)
}
}
public class Main {
psvm(String[] args){
// init
Node head = new Node(1); //任意建了一个值为1的头节点
Node head.next = new Node(2);
Node head.next.next = new Node(3);
Node head.next.next.next = new Node(4);
// 遍历
for (int p = head; p != null; p=p.next){
// 做些事
System.out.println(p.val);
}
}
}
后续TBC