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 8836633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:32:25+00:00 2026-06-14T09:32:25+00:00

I am to java and I am trying to implement a remove from double

  • 0

I am to java and I am trying to implement a remove from double linked list method but I am struggling and not sure how to advance. The method removes data stored at the given node in the list. I have read that I need to account for cases where the the element being removed is the start or end but I am not sure how to go about. In general I am not sure if this is the right way to do it. My code/progress is posted below. If any could help, it would be appreciated. Thanks

P.S. I have a start and an end reference within the class and a size reference

 public type removeAtTheIndex(int index) 
  {
     type theData = null;
    Node <type> current= start;
    Node temp= new Node();
    if (index >= 0 && index < size && start !=null)
    {

        for (int i=0; i < index && current.getNext()!= null; i++)
        {
            current=current.getNext();
        }
        if (current != null)
        {
        if (current == start)
        {

        }

        else if (current == end)
        {

         }

        else
        {
            theData= current.getData();
            temp= current.getPrev();
            temp.setNext(current.getNext());
            current.getNext().setPrev(temp);
            current.setData(null);
            size--;

        }

    }

    return theData;
}
  • 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-06-14T09:32:26+00:00Added an answer on June 14, 2026 at 9:32 am

    I have changed the type to Type. Using lowercase for class names is not recommended in Java. I have added loads of comments in the hope that you will understand what is going on.

    Note that this is not tested code. You may find bugs in it but I am confident that the essence of process is there.

    public Type removeAtTheIndex(int index) {
      // I want to return the data that was removed.
      Type theData = null;
      // Sanity checks.
      if (index >= 0 && index < size && start != null) {
        // Find the entry with the specified index.
        Node<Type> current = start;
        for (int i = 0; i < index && (current = current.getNext()) != null; i++) {
        }
        // Did we find it?
        if (current != null) {
          // Yes! Gather the contents.
          theData = current.getData();
          // Clear it.
          current.setData(null);
          // Special?
          if (current == start) {
            // Its the start one.
            start = start.getNext();
            // Detach it.
            start.setPrev(null);
          } else if (current == end) {
            // Step end back one.
            end = end.getPrev();
            // Detach it.
            end.setNext(null);
          } else {
            // Remove from within list.
            Node prev = current.getPrev();
            // Point it at my next.
            prev.setNext(current.getNext());
            // Point my next to new prev.
            current.getNext().setPrev(prev);
          }
          // One less now.
          size--;
        }
      }
      return theData;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to implement the linked list data structure using java, it works
I am trying to remove an item from the LinkedList in java. This List
I'm trying to implement my own List system in Java. the List class file
I am trying to implement a Stack in java (using the list interface: Interface
I'm trying to implement RSA Encryption in both Java and PHP, but I can't
I am trying to implement A* in Java but i have hit a brick
I am trying to implement the Java 1.6 Queue interface, but I am getting
I'm trying implement my project in Apache Struts 2 but I'm not very familiar
I am trying to implement a linked tree but I am getting a nullpointer
I trying to implement the active record pattern using Java/JDBC and MySQL along with

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.