java代码实现链表

    xiaoxiao2021-03-25  104

    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; } }
    转载请注明原文地址: https://ju.6miu.com/read-22700.html

    最新回复(0)