Answer the question
In order to leave comments, you need to log in
Why is the CW stitch being repeated?
Good afternoon. I'm learning C# and ran into some misunderstanding about how a function works.
At the moment I am solving problems using algorithms, namely, bypassing a binary tree.
Binary tree class:
class Node<T>
{
public int Value;
public Node<T> Left;
public Node<T> Right;
}
public void InsertValues(int value)
{
if (value > Value)
{
if (Right is null)
Right = new Node<T> { Value = value };
else
Right.InsertValues(value);
}
else
{
if (Left is null)
Left = new Node<T> { Value = value };
else
Left.InsertValues(value);
}
}
public void Infix(Node<T> node)
{
if (node.Left != null)
{
Infix(node.Left);
}
Console.WriteLine(node.Value);
if (node.Right != null)
{
Infix(node.Right);
}
}
class Program
{
static void Main(string[] args)
{
Node<int> node = new Node<int> { Value = 2 };
node.InsertValues(3);
node.InsertValues(1);
node.Infix(node);
}
}
Answer the question
In order to leave comments, you need to log in
There is no cycle here. And there is recursion. Learn how recursion works
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question