Elad770
Member
- Joined
- Oct 4, 2021
- Messages
- 20
- Programming Experience
- 1-3
Hello I have a problem with tree,
I want to change the root of the tree that has two nodes left and right. To solve this there is the classic solution that c# proposes to move the object to the function as a ref, but the problem is that because the function is recursive and I always call the function with the left hand and once with the right hand,
I can not pass the node to a function in this way
It also has a solution define variable that will save the left node and send it via ref and the same with the right node. The point in the logic of my code is it conflicts with all sorts of little things. Is there a simple way without defining a variable and assigning it?
I want to change the root of the tree that has two nodes left and right. To solve this there is the classic solution that c# proposes to move the object to the function as a ref, but the problem is that because the function is recursive and I always call the function with the left hand and once with the right hand,
I can not pass the node to a function in this way
C#:
private void AnalyzeTree(ref Node tree)
{
if (tree == null || tree.OpratorOrOprend==")")
{
return;
}
if (tree.OpratorOrOprend == "(")
{
tree = tree.Left;
}
/*Here i get a complication error
A property or indexer may not be passed as an out or ref */
AnalyzeTree(ref tree.Left);
AnalyzeTree(ref tree.Right);
//next code ....
}