Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7600743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:59:11+00:00 2026-05-30T22:59:11+00:00

I am trying too delete a node in a doubly linked list, by an

  • 0

I am trying too delete a node in a doubly linked list, by an index that a user inputs. It seems to make sense for me but after “removing the node” and reprinting the list’s contents, nothing has changed. I’m sure it’s something stupid that I’m missing. Any advice?

public void removeEntryNode() {
    System.out
            .println("We delete by index here. Type in the number you want to delete");
    // print list for selection
    temp = head;
    while (temp != null && temp.getFirstName() != null) {
        System.out.print(temp.getIndex() + " " + temp.getFirstName() + " ");
        System.out.print(temp.getLastName() + " ");
        System.out.println(" ");
        temp = temp.getNext();
    }

    int selection = keyboard.nextInt();

    // Gets node matching index with selection and deletes it
    // Next two lines loop through list
    while (temp != null && temp.getIndex() != selection) {
        temp = temp.getNext();
    }

    // if it is the head
    if (selection == 0) {
        head = temp.getNext();
        temp.getNext().setPrev(null);
        temp.setNext(null);
        counter--;
    }
    // if it is the tail
    else if (selection == size()) {
        tail = temp.getPrev();
        temp.setPrev(null);
        temp.setNext(null);
        temp.getPrev().setNext(null);
        counter--;
    } else {
        temp.getPrev().setNext(temp.getNext());
        temp.getNext().setPrev(temp.getPrev());
        temp.setNext(null);
        temp.setPrev(null);
        counter--;
    }

    System.out.println("Successfully deleted ");
    menu();
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T22:59:12+00:00Added an answer on May 30, 2026 at 10:59 pm

    It’s impossible to pinpoint the exact problem without seeing your entire code.

    Nonetheless, I’ll give you some pointers:

    1.

    ... temp.getIndex() != selection ...
    

    It is generally not a good idea for an element in a linked list to keep track of its own index. To keep the indices correct, every insertion or removal would require traversing the list just to update the indices.

    2.

        else if (selection == size()){
    

    There is probably an off-by-one error here.

    3.

            temp.setPrev(null);
            temp.setNext(null);
            temp.getPrev().setNext(null);
    

    The last line is guaranteed to throw a NullPointerException.

    Once you fix these problems, I recommend stepping through your program in a debugger, to see whether what actually happens is what you expect to happen at each step.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to delete / remove a image from my image list. I'm too
Trying to parse some XML but apparently this is too much for a lazy
I probably spend far too much time trying to make my visual interfaces look
I'm trying to show programmers that some captchas are too weak, and i'm breaking
I'm not too familiar with networking in JAVA but what i'm basically trying to
My problem is deleting a node from linked list. I have two structs :
I'm trying to make a delete confirmation action sheet like what you see in
I hope the title is not too confusing. I am trying to make folders
I'm trying to find a way with a batch file that will delete specific
Im having an error that says: Request-URI Too Large Actually I'm trying to add

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.