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

java实现删除链表的中间节点,第1张

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实现删除链表的中间节点的详细内容,

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/686961.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-21
下一篇 2022-04-21

发表评论

登录后才能评论

评论列表(0条)

保存