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

  • SEARCH
  • Home
  • 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 7546019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:05:28+00:00 2026-05-30T09:05:28+00:00

I am trying to Implement a doubly linked with null objects at the beginning

  • 0

I am trying to Implement a doubly linked with null objects at the beginning and end of the list using null object design pattern. So an empty list will contain two null objects. So I wrote this code Does this follow null object design pattern? If not how can I achieve that. ANy suggestions will be appreciated.

Updated Code-

// Creating a doubly linked list.
        doubleLinkedList = new DoubleLinkedList();

    class DoubleLinkedList {

        private NewLink firstNode;
        private NewLink lastNode;
        private NewLink rootNode;



        public DoubleLinkedList() {

//So this satisfies my question that I have asked meaning null objects at beginning and last node or something else I have to do.
            firstNode = NewLink.NULL_NODE;
            lastNode  = NewLink.NULL_NODE;

        }

    }



    class NewLink {

        public String  data;
        public NewLink nextPointer;
        public NewLink previousPointer;


public static final NewLink NULL_NODE = new NewLink(); 



        public NewLink(String id) {

            data = id;

        }

public NewLink() {

    }
        // Overriding toString method to return the actual data of the node
        public String toString() {

            return "{" + data + "} ";

        }
    }
  • 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-30T09:05:29+00:00Added an answer on May 30, 2026 at 9:05 am
    public static final NewLink NULL_NODE = new NewLink(); 
    

    must be in NewLink class

    so

    firstNode = NewLink.NULL_NODE;
    secondNode = NewLink.NULL_NODE;
    

    also you can make all methods from NewLink – abstract
    and make two nested classes: for NULL objects and for not NULL object.
    It’s can be very helpful in difficult situations

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

Sidebar

Related Questions

I'm trying to implement doubly-linked list in c++ and right now I'm adding iterator
I am trying to Implement a Doubly Circularly linked list, and am a little
I am trying to implement a linked-list in C++. Currently, I have the following
I wrote the following code when trying to make a doubly-linked list with an
Trying to implement a function that will return a list of ints the represent
I'd like to implement a stack using a linked list. In order to implement
I am trying to implement a short converter using TinyXML that will take an
trying to implement a dialog-box style behaviour using a separate div section with all
Trying to implement the decorator pattern in C# from the code in the Head
I have been trying to implement hash-tables using uthash.h, following the (excellent) documentation I

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.