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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:41:57+00:00 2026-05-26T12:41:57+00:00

This is the struct: struct Node { Node *nodes[MAX] }; So inside the struct,

  • 0

This is the struct:

struct Node {
    Node *nodes[MAX]
};

So inside the struct, we have an array of pointers to more Node structures, and so on.

Basically the initial node is allocated for (using new Node), and then we allocate space for any Node that we need to use.
ie.

Node *full = new Node();
Node *another = new Node();
full->nodes[30] = another;

All other pointers are set to NULL.

Since I did not use any new [] anywhere, I don’t need to use delete [], correct?

  • 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-26T12:41:58+00:00Added an answer on May 26, 2026 at 12:41 pm

    You can add a constructor and a destructor to your Node struct:

    struct Node {
        Node *nodes[MAX];
        Node()
        {
            for (int i = 0; i < MAX; i++)
                nodes[i] = 0;
        }
        ~Node()
        {
            for (int i = 0; i < MAX; i++)
                delete nodes[i];
        }
    private:
        // disable copies/assignments
        Node(const Node&);
        Node& operator=(const Node&);
    };
    

    So now you just need to delete the root node and all the children will get recursively deleted at the same time. Note that the constructor is there to ensure the array is zeroed out. You don’t want to end up calling delete on uninitialized memory! Also note that calling delete on NULL is a valid operation that does nothing (if you use the standard allocator).

    EDIT: even though you say in the comments that you don’t care, it might be a good idea to disable copies and assignments in your struct, as I’ve done above. This will prevent you from shooting yourself in the foot and deleting the same memory twice.

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

Sidebar

Related Questions

I have a linked list of Nodes, each Node is defined as: struct Node
I have this struct: struct Map { public int Size; public Map ( int
I have this struct; #define BUFSIZE 10 struct shared_data { pthread_mutex_t th_mutex_queue; int count;
I have a large number of instances of a C structure like this: struct
For example, I have a struct which is something like this: struct Test {
I have this code struct Student { char name[48]; float grade; int marks[10,5]; char
I'm using a struct like this: define struct _Fragment{ int a; char *seq; }Fragment;
This question is more a semantic-algorithmic-data-structure question than a F# syntactically question. I have
I have problems understanding why when I create two or more nodes (as shown
I have a linked list of structures. Lets say I insert x million nodes

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.