public class MySingleList {
public MySingleList() {
this.head = null;
}
class Node{
private int data;
public Node next;
public Node(int data) {
this.data = data;
this.next = null;
}
public int getData() {
return data;
}
public Node getNext() {
return next;
}
}
public Node getHead() {
return head;
}
private Node head;
int size;
}
2. 头插
public void addFirst(int data) {
Node node = new Node(data);
//第一次插入数据
if(this.head==null){
this.head = node;
}else {
node.next = head;
head = node;
}
size++;
}