您的位置:首页 > 编程语言 > Java开发

java代码实现链表

2017-04-04 19:09 447 查看

java代码实现链表

```
public class Node {
public int data;//数据
public Node next;//指向下一个结点的指针

public Node(int data) {
this.data = data;
}
}


public class NodeList {
private Node head;//头结点

public NodeList(Node head) {
this.head = head;
}
//添加结点
public void addNode(int data){
Node newNode = new Node(data);
if (head == null){
head = newNode;
return;
}
Node tmp = head;
while(tmp.next != null){
tmp = tmp.next;
}
tmp.next = newNode;
}
//删除结点
public void delNode(Node node){
if (node == null){
return;
}
node.data = node.next.data;
node.next = node.next.next;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  链表