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如果删除链表的中间节点内容对大家有帮助,同时也希望大家多多支持亿速云,关注行业资讯频道,遇到问题就找亿速云,详细的解决方法等着你来学习!