Re: Specific Cloning Question




Oliver Wong wrote:
"Alex" <alexander.webb@xxxxxxxxx> wrote in message
news:1158920061.757641.292170@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

3) If I am satisfied with the new tree can I not simple set the old
tree equal to the new tree?

Probably not. You can't "set" an object. You can set the value of a
reference (i.e. to point to the new tree instead of the old tree), but that
will not update all the other references to the old tree.

There are more time-optimal ways of doing this, but without further
information, the best I can come up with is to clone the tree, apply the
operation on the clone, test if it satisfies whatever you want, and if it
does, re-apply the operation on the old tree. Discard the clone in either
cases.


The reason I have not managed to cut down the program is that I am not
sure how to do that without losing the complexity that is causing the
problem. I have made smaller versions of things and tried cloning
things that contain lists of references but I don't seem to get the
problems in these oversimplified examples.

What's this about "lists of references"? This is the first time you
mention it, AFAIK. Previously you said only that the tree has a reference to
its parent, and its children. Being a binary tree, this means exactly 3
references in every node.


Anyway, if your time is too valuable there is no pressure on you or
anyone else to help or to even read this. However, I fail to see that
there is much harm in asking, just in case someone out there knows how
to help and has some time to do it.

Have you considered a recursive solution?

- Oliver

No,

The trees consist of nodes, and each node has a reference to its parent
and children. Each tree is made up of lots of nodes, hence a list of
them.
Sorry if that was unclear.

I am not entirely sure what you mean by a "recursive solution". I have
tried cloning the tree by cloning all the nodes in it. However the
problem here is that when I try to clone Node A it has a reference to
Node B as its parent so Node B gets cloned. But when I am cloning Node
B, it has a reference to Node A as its child it goes back to trying to
clone A again.

Alex

.



Relevant Pages

  • Re: Specific Cloning Question
    ... tried cloning the tree by cloning all the nodes in it. ... problem here is that when I try to clone Node A it has a reference to ... Alternatively, you could wrap all your nodes in an actual Tree object, ... public MyNode subtreeCopy{ ...
    (comp.lang.java.help)
  • Re: Specific Cloning Question
    ... tried cloning the tree by cloning all the nodes in it. ... problem here is that when I try to clone Node A it has a reference to ... it has a reference to Node A as its child it goes back to trying to ... Alternatively, you could wrap all your nodes in an actual Tree object, ...
    (comp.lang.java.help)
  • Re: Exposing contained types.. Especially LISTS
    ... Code may want to interact with A's methods (add ... the original and permanent" "holder" to the reference to TheList, ... Now one can navigate up and down the tree easily using ... This is a case where the clients now all talk to to navigate the ...
    (comp.object)
  • Re: Specific Cloning Question
    ... tried cloning the tree by cloning all the nodes in it. ... problem here is that when I try to clone Node A it has a reference to ... Node B as its parent so Node B gets cloned. ... Alternatively, you could wrap all your nodes in an actual Tree object, and put a clone method on the tree, and not on any of the nodes themselves, and have the tree orchestrating the cloning of the nodes. ...
    (comp.lang.java.help)
  • Re: MFC Newbie design question
    ... > without increasing the reference count. ... At the end of the day the tree node ... > locate the correct XML node object and update it accordingly. ... >> The loaded document will be displayed in a TreeView. ...
    (microsoft.public.vc.mfc)