首页  >  文章  >  Java  >  java实现删除链表的中间节点

java实现删除链表的中间节点

王林
王林转载
2020-10-23 15:43:552272浏览

java实现删除链表的中间节点

目的:

删除链表的中间节点

(推荐教程:java课程

代码实现:

public class Node{
    public int value;
    public Node next;
    public Node(int data){
        this.value=data;
    }
}
public Node removeMidNode(Node head){
    if(head==null||head.next==null){
        return head;
    }
    if(head.next.next==null){
        return head.next;
    }
    Node pre=head;
    Node cur=head.next.next;
    while(cur.next!=null&&cur.next.next!=null){
        pre.pre.next;
        cur=cur.next.next;
    }
    pre.next=pre.next.next;
    return head;
}

相关推荐:java入门

以上是java实现删除链表的中间节点的详细内容。更多信息请关注PHP中文网其他相关文章!

声明:
本文转载于:csdn.net。如有侵权,请联系admin@php.cn删除