// 节点类
class Node {
public int val;
public Node next;
public Node(int val) {
this.val = val;
}
}
public class MyLinkedList {
public Node head;
public MyLinkedList() {
this.head = null;
}
//头插法
public void addFirst(int data){
Node node = new Node(data);
if(head == null) {
this.head = node;
return;
}
node.next = this.head;
this.head = node;
}
//尾插法
public void addLast(int data){
Node node = new Node(data);
if
06-17
650
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交