找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索本站精品资源

首页 教程频道 查看内容

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

作者:模板之家 2020-10-25 17:14 14238人关注

本文为大家分享了删除链表的中间节点的方法,具有一定的参考价值,希望可以帮助到大家。

目的:

删除链表的中间节点

(推荐教程: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实现删除链表的中间节点的详细内容,更多请关注模板之家(www.mb5.com.cn)其它相关文章!


路过

雷人

握手

鲜花

鸡蛋
来自: 网络收集

全部回复(0)