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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:50:47+00:00 2026-05-16T14:50:47+00:00

I have a tree of objects, where each object has a std::vector of pointers

  • 0

I have a tree of objects, where each object has a std::vector of pointers to its children. The class of the object has a rewrite() method that is recursively applied to alter the object and its children, typically with the following transformations, where [N] is the object being rewritten and (M) is the element that rewrite() returns:

                 (A)
 [A]             / \               [A]
 / \     -->    B   X               |    -->    (B)
B   C                \              B
                      C

What’s the cleanest way of extending this setup to allow transformations like this?

    A             X
    |            / \
   [B]   -->    C   A
    |               |
    C              (Y)

That is, those that re-root the tree, move an element, insert a new element, and return the inserted element. I’m having a hard time coming up with something nice that also involves minimal refactoring. Thoughts?

  • 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-16T14:50:48+00:00Added an answer on May 16, 2026 at 2:50 pm

    Looks like, for speed, you’ll need a “back-pointer” from each child node to its parent node. This way you can follow the chain of parent pointers given a pointer to any node all the way to the root, if that’s what you need (I’m not sure how else you planned to find the root given just a pointer to an inner node, without backpointers?). Of course, you’ll need to adjust the back pointer, as well as the “children” std::vector, whenever you rearrange the tree — an unfortunate consequence of the slight duplication of information (no more than, say, a doubly linked list presents;-), but a small price to pay for the ease and speed of such bidirectional navigation.

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

Sidebar

Related Questions

I have a tree that consists of several objects, where each object has a
I have a tree-like object structure that consists of two types of objects: object
As input I have list of all objects where each object has properties: name
So i have an application that creates like 2000 objects. For each object, it
Let's say I have circular objects. Each object has a diameter of 64 pixels.
I have a large array with around 20k objects in it. Each object has
If I have a form-backing object that has a complicated object tree -- say
In Lua, I have a tree relationship structure between objects where an object can
I have a tree-like object, managed by Hibernate. The object has a list of
I have a Binary Search Tree, I use template to add any class 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.