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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:08:39+00:00 2026-06-16T00:08:39+00:00

I have to implement double linked lists. The method prepend should insert a new

  • 0

I have to implement double linked lists. The method prepend should insert a new element bevor the existing list. But I dont know how to link the reference “next” of the new element with the reference “prev” of the old list.
Thanks in advance.

public class DoublyLinkedList {

private String info;
private DoublyLinkedList next;
private DoublyLinkedList prev;

public DoublyLinkedList(String info) {
    this.info = info;
    this.next = this.prev = null;
}

private DoublyLinkedList(String info, DoublyLinkedList prev, DoublyLinkedList next) {
    this.info = info;
    this.prev = prev;
    this.next = next;
}

DoublyLinkedList prepend(String info) {
    // Beginning of a list, insert new element
    if (prev == null) {
        prev = new DoublyLinkedList(info, null, next);
    } else {
        prev.prepend(info);
    }
    return prev;
}
  • 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-16T00:08:40+00:00Added an answer on June 16, 2026 at 12:08 am

    You need to link the new node with the current node by setting the next_link of the new node with the current node.

    public class DoublyLinkedList {
        ...
        DoublyLinkedList prepend(String info) {
            // Beginning of a list, insert new element
            if (prev == null) {
                // this is the changed line.
                prev = new DoublyLinkedList(info, null, this);
            } else {
                prev.prepend(info);
            }
            return prev;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have tried to implement doubly linked list in C++. Here is the code,
I have an assignment that requires us to implement a doubly linked list class.
I am trying to implement a Circular Doubly Linked List, and I have no
So I have a self-made double-linked-list implementation that is being used as a stand
I am trying to implement a linked-list in C++. Currently, I have the following
clients :has_many :project,:roles I have implement but its not a good implementation..
I'm attempting to implement a stack using a linked list. My stack constructor createStack()
I am trying to Implement a Doubly Circularly linked list, and am a little
Possible Duplicate: Single Linked List is Palindrome or not Suppose i have a link
I remember stumbling onto a list of basic algorithms to implement in a new

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.