java代码实现链表

来源:互联网 发布:代运营淘宝如何收费用 编辑:程序博客网 时间:2024/06/06 08:37

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;    }}
0 0
原创粉丝点击