Home > Java > Javagetting Started > Java implements deleting the intermediate node of a linked list

Java implements deleting the intermediate node of a linked list

王林
Release: 2020-10-23 15:43:55
forward
2395 people have browsed it

Java implements deleting the intermediate node of a linked list

Purpose:

Delete the intermediate node of the linked list

(Recommended tutorial: java course)

Code implementation:

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;
}
Copy after login

Related recommendations: Getting started with java

The above is the detailed content of Java implements deleting the intermediate node of a linked list. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template