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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T20:11:25+00:00 2026-06-07T20:11:25+00:00

I’m currently writing a program that (as of right now) utilizes about five linked

  • 0

I’m currently writing a program that (as of right now) utilizes about five linked lists, and there’s about 50 functions that modify or otherwise use those linked lists. I am somewhat torn on how exactly the head node should be implemented.

Implementation #1 Using a dummy head node

If I create a dummy head node, the headNode never has to be deleted, even if there is no data for that linked list to represent. Below are two different possible linked lists showing this idea.

Format: (object)--name_of_pointer_to_next_object--> (next object)
(headNode)--headNode.pNext--> (Nothing/NULL)
(headNode)--headNode.pNext--> (dataNode1)--dataNode1.pNext--> (dataNode2)--dataNode2.pNext--> (Nothing/NULL)

The benefit of this implementation is that, for functions that work with the linked lists, they don’t have to have special code for the case where the head node is Nothing or (in c++), NULL. Below is an example of appending a node onto the end of the linked list using this implementation.

Public Function AppendNode(theLinkedList as NODE_, theNewNode as NODE_)
    dim lastNode as NODE_

    Set lastNode = theLinkedList

    Do While Not lastNode.pNext Is Nothing
        Set lastNode = lastNode.pNext
    Loop

    Set lastNode.pNext = theNewNode 
End Function

Implementation #2 headNode can be deleted

If I allow the headNode to be deleted, this poses problems and increases the volume of code that I have to write. Below is the same set of data, except this time the head is a legitimate node that contains data.

Format: (object)--name_of_pointer_to_next_object--> (next object)
(Nothing/NULL)
(dataNode1)--dataNode1.pNext--> (dataNode2)--dataNode1.pNext--> (Nothing/NULL)

And here is the same function, except that this time it has to beware of the possibility that the head node is Nothing/NULL.

Public Function AppendNode(theLinkedList as NODE_, theNewNode as NODE_)
    dim lastNode as NODE_

    If theLinkedList Is Nothing Then
        Set theLinkedList = theNewNode 
    Else
        Set lastNode = theLinkedList

        Do While Not lastNode.pNext Is Nothing
            Set lastNode = lastNode.pNext
        Loop

        Set lastNode.pNext = theNewNode 
    End If
End Function

Obviously, I am leaning towards Implementation #1. It requires at least 4 less lines of code each time I want to use the linked lists (considering the fact that I will do this hundreds of times, you can multiply that 4 lines by 300 or so; e.g. it will save me from writing 1,200 lines of code), AND perhaps most importantly, it will cut down on the amount of state my program has. All of the possible states that my program will be in will only require me to look for pNext Is Nothing, and reducing the amount of state is greatly appreciated at this point because this program is going to be a monster that will end up being around 20k lines of rather complicated code that has to deal with a lot of state.

Am I wrong in thinking that Implementation #1 is the best way to do this? I can’t come up with a single reason why Implementation #2 would be superior.

  • 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-07T20:11:27+00:00Added an answer on June 7, 2026 at 8:11 pm

    It is very common (though not required) to have a special, reserved node at the start and end of a linked list. It is typically called a sentinel node.

    As an aside, I suggest taking the “about 50 functions that modify or otherwise use those linked lists” and moving them to a Class that encapsulates them.

    You should not have code that looks like this:

    Dim theLinkedList as NODE_
    Set theLinkedList = New NODE_
    
    'bunch of work with the list
    'bunch of work with the list
    'bunch of work with the list
    
    Dim theNewNode as NODE_
    Set theNewNode = New NODE_
    Set theNewNode.Next = someDataObject
    
    Call AppendNode(theLinkedList, theNewNode)
    

    Instead the code should just look like this:

    Dim theList As LinkedList
    Set theList = New LinkedList
    
    'etc
    
    Call theList.Append(someDataObject)
    

    See the difference? The LinkedList calss wraps and hides the details. It can handle things like whether there is a sentinel node at the head or tail as well so that all the rest of your project’s code is blissfully unaware.

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

Sidebar

Related Questions

this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I am reading a book about Javascript and jQuery and using one of the
I want use html5's new tag to play a wav file (currently only supported

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.