Doubly linked list remove at index Chi tiết

Doubly linked list remove at index Chi tiết

Kinh Nghiệm về Doubly linked list remove index Mới Nhất


You đang tìm kiếm từ khóa Doubly linked list remove index được Update vào lúc : 2022-12-14 12:13:07 . Với phương châm chia sẻ Bí kíp về trong nội dung bài viết một cách Chi Tiết 2022. Nếu sau khi đọc tài liệu vẫn ko hiểu thì hoàn toàn có thể lại Comment ở cuối bài để Mình lý giải và hướng dẫn lại nha.


JAVA Program for Deletion from Nth Position of a Doubly Linked List


July 16, 2022


Nội dung chính


  • JAVA Program for Deletion from Nth Position of a Doubly Linked List

  • JAVA Program to Delete a Node from the Nth Position of a Doubly Linked Last

  • Steps to be followed while Deleting a Node from the Nth Position of a Doubly Linked List

  • Algorithm to be used for the Deletion of a Node from a Specific Index of a Doubly Linked List

  • Java Program for Deletion from the Nth Position of a Doubly Linked List


  • JAVA Program to Delete a Node from the Nth Position of a Doubly Linked Last


    In this page well take a look a comprehensive explanation of Deleting a Node from a specific index of a Doubly Linked List, one of the most widely used operation on a Doubly Linked List


    Example: If we have a list (10 > 20 > 30 > 40 > 50) and we have to delete a node on the Second Index of the List, that is i=2, then after deleting a node. Updated Linked list will be (10 > 20 > 40 > 50) . We will be learning more about the whole process in the explanation below.


    JAVA Program to Delete a Node from the nth position of a doubly Linked ListJAVA Program to Delete a Node from the nth position of a doubly Linked List


    Steps to be followed while Deleting a Node from the Nth Position of a Doubly Linked List


    • Check for the presence of Node in the List, if there exists some Nodes, Continue.

    • Now, to delete a node from Nth position of the Doubly Linked List, well have to delete and redirect various links of the Linked List.

    • First of all the next pointer of the (n-1)th Node of the Linked List will now point to the address of the (n+1)th node of the Doubly Linked List.

    • Now the Previous Pointer of the (n+1)th Node of the Linked List will now be re-directed to the address of (n-1)th node of the List.

    JAVA Program for Deletion from the nth node in a Doubly Linked ListJAVA Program for Deletion from the nth node in a Doubly Linked List


    Algorithm to be used for the Deletion of a Node from a Specific Index of a Doubly Linked List


    • IF(HEAD == NULL)
      • RETURN


    • ELSE
      • NODE CURRENT = HEAD;

      • INT POS =N;


    • FOR(INT I = 1; I < POS; I++)
      • CURRENT = CURRENT.NEXT


    • IF(CURRENT == HEAD)
      • HEAD = CURRENT.NEXT


    • ELSE IF(CURRENT == TAIL)
      • TAIL = TAIL.PREV


    • ELSE
      • CURRENT.PREV.NEXT = CURRENT.NEXT

      • CURRENT.NEXT.PREV = CURRENT.PREV


    • CURRENT = NULL

    Java Program for Deletion from the Nth Position of a Doubly Linked List


    public class PrepInsta


    class Node

    int data;

    Node prev;

    Node next;

    public Node(int data)

    this.data = data;


    public void display()

    Node temp = head;

    while (temp != null)

    System.out.print(temp.data + “>”);

    temp = temp.next;


    System.out.println(“END”);


    Node head, tail = null;

    public void addNode(int data)

    Node newNode = new Node(data);

    if(head == null)

    head = tail = newNode;

    head.prev = null;

    tail.next = null;


    else

    tail.next = newNode;

    newNode.prev = tail;

    tail = newNode;

    tail.next = null;


    public void deletenth(int n)

    if(head == null)

    return;


    else

    Node current = head;


    int pos =n;


    for(int i = 1; i < pos; i++)

    current = current.next;


    if(current == head)

    head = current.next;


    else if(current == tail)

    tail = tail.prev;


    else

    current.prev.next = current.next;

    current.next.prev = current.prev;


    current = null;


    void print()

    Node curr = head;

    if(head == null)

    System.out.println(“List is empty”);

    return;


    while(curr != null)


    System.out.print(curr.data + ” “);

    curr = curr.next;


    System.out.println();


    public static void main(String[] args)

    PrepInsta dList = new PrepInsta();

    dList.addNode(10);

    dList.addNode(20);

    dList.addNode(30);

    dList.addNode(40);

    dList.addNode(50);

    System.out.println(“Initial Doubly Linked List: “);

    dList.print();

    dList.deletenth(2);

    System.out.println(“Doubly Linked List after Deletion from nth Position: “);

    dList.print();


    Initial Doubly Linked List:

    10 20 30 40 50

    Doubly Linked List after Deletion from nth Position:

    10 30 40 50

    Deletion from the Beginning of a Doubly Linked ListDeletion from the End of a Doubly Linked List


    Login/Signup to comment


    Reply

    0

    0

    Chia sẻ


    Chia Sẻ Link Cập nhật Doubly linked list remove index miễn phí


    Bạn vừa tìm hiểu thêm nội dung bài viết Với Một số hướng dẫn một cách rõ ràng hơn về Review Doubly linked list remove index tiên tiến và phát triển nhất Share Link Cập nhật Doubly linked list remove index Free.



    Hỏi đáp vướng mắc về Doubly linked list remove index


    Nếu sau khi đọc nội dung bài viết Doubly linked list remove index vẫn chưa hiểu thì hoàn toàn có thể lại phản hồi ở cuối bài để Admin lý giải và hướng dẫn lại nha

    #Doubly #linked #list #remove #index

Related posts:

Post a Comment

Previous Post Next Post

Discuss

×Close