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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:43:26+00:00 2026-06-13T14:43:26+00:00

I am developing an editor for some kind of binary tree structure and I

  • 0

I am developing an editor for some kind of binary tree structure and I need to have an undo function. I thought about using the command pattern to achieve this. However, I was yet unable to find a way to use the command pattern with my binary tree structure.

The binary tree structure is made up via pointers. So a node knows its parent and its children. When I now want to add a node I would construct a NodeAdd object with the parent as parameter and pass it to the UndoStack. In order to remove an existing node a NodeRemove object would be passed to the UndoStack with a pointer to the Node as parameter. Both, the NodeAdd and NodeRemove would have to implement undo() and redo() (where redo() is called when the object is put on the UndoStack).

The problem I am facing is, dealing with the situation when a node removal and then the addition of this same node should be undone:

  1. redo NodeAdd
  2. redo NodeRemove
  3. undo NodeRemove
  4. undo NodeAdd

Once the redo NodeRemove is executed the Node object is destroyed. In the undo NodeRemove a new Node object can be constructed again, but undo NodeAdd could not be executed as it does not have the pointer to the newly constructed Node.

I think I am trying to use the command pattern in the wrong way. I probably should destroy or construct the Node objects rather within the commands’ constructor/destructor than within undo()/redo(). Unfortunately, I have no idea how to do this with this kind of structure and all examples and advices I could find are related to text editing or editing something where you have not a dynamic structure with pointers.

Any ideas how to approach this problem?

  • 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-13T14:43:27+00:00Added an answer on June 13, 2026 at 2:43 pm

    One option would be to have your Command objects refer to their operands by some unique identifier (say an index represented as a size_t) instead of by memory address which, as you’ve discovered, can fluctuate.

    Then, by maintaining an unordered_map< size_t, Node* > somewhere (say a static member of Node for example), your Command objects can obtain the current embodiment of a given Node and add/remove/manipulate it as necessary.

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

Sidebar

Related Questions

Developing a project of mine I realize I have a need for some level
I am developing game editor in c++.I have implemented reflection mechanism using DiaSDK.Now I
I'm developing a canvas graphical editor. I have already coded an undo-redo system that
HI, I am developing an editor using RichTextBox in WPF, i have to implement
I have been developing a toy editor, and I want my editor to look
Hi i am developing game level editor.Currently I am using win32 with directX.But with
I have a question about implementing WYSIWYG editors into CakePHP. I'm developing an intranet
I'm developing an eclipse plugin and I need to, programmatically, instantiate a Java Editor.
I am developing an API for some application. And I need to attach there
I'm developing a report in Crystal Reports and need to render some math formulas

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.