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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:20:17+00:00 2026-05-25T15:20:17+00:00

Lets say you have 2 classes: – Node – Doubly linked list (DLL) Your

  • 0

Lets say you have 2 classes:

 - Node
 - Doubly linked list (DLL)

Your main creates a bunch of nodes, who know something about themselves, like their name for example and then calls add(Node*) method of the DLL.

In order to keep track of these Node pointers, (i would think) DLL should maintain an array of them. Is there a way to avoid it? (or any other data structure for that matter)

How is DLL implemented under the hood? Does it use arrays or something else?

  • 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-25T15:20:17+00:00Added an answer on May 25, 2026 at 3:20 pm

    There is a way to avoid it. You in fact don’t need to keep track of all the pointers in the one spot at all, because the Nodes themselves ARE the data structure.

    EDIT: Just saw your Objective-C comment.

    The Node should have (Objective-C syntax):

    // the actual info at this list index
    @property (retain) id ptr;
    
    @property (retain) Node *previous;
    @property (retain) Node *next;
    

    And then your DLL class is simply a class with:

    @property (retain) Node *first;
    @property (retain) Node *last;
    @property (assign) NSUInteger count;
    

    That’s all you need. Inserting or deleting a Node involves pointer shuffling and a count adjustment, and access is sequential from either end.

    add:(Node*)newNode would literally be:

    [newNode setPrevious:[self last]];
    [[self last] setNext:newNode];
    [self setLast:newNode];
    [self setCount:[self count]+1];
    

    ..whereas add:(Node*)newNode atIndex:(NSUInteger)index would be a little more complex:

    if(index > self.count)
    {
        // maybe throw an exception or something
    } else if(index == self.count) // just do the normal add
    {
        [self add:newNode];
        return;
    } else if(index == 0) { // front-insert is also easier
        [newNode setNext:[self first]];
        [[self first] setPrevious:newNode];
        [self setFirst:newNode];
        [self setCount:[self count]+1];
        return;
    }
    
    // maybe do an extra check to see if it's quicker to search from the end
    Node *currentLocation = [self first];
    NSUInteger idx;
    for(idx = 0; i < (index - 1); ++idx)
    {
        currentLocation = [currentLocation next];
    }
    
    Node *previousNode = currentLocation; // store a reference to the previous node
    currentLocation = [currentLocation next]; // now at the point we want to insert
    
    [previousNode setNext:newNode];
    [newNode setPrevious:previousNode];
    [newNode setNext:currentLocation];
    [currentLocation setPrevious:newNode];
    
    [self setCount:[self count]+1];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

for clarity lets say we have students and classes, its a many to many
Lets say i have the following c# classes: abstract class a { protected abstract
Lets say you have some functions in some classes are called together like this
So, lets say I have two nearly identical classes in C# and Ruby: C#
Lets say I have two classes: class A { [SortOrder(3)] public string Name {
Lets say I have three django model classes - lets call them A, B
Lets say we have a program which contains such classes: public interface AbstractItem {
Lets say I have a java package commands which contains classes that all inherit
I'm learning grails, and I have a problem. I have 2 classes, lets say:
Lets say I have 3 classes: class A { void do_A() { //Check object

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.