Exemple #1
0
        public Node FindRecursive(int value)
        {
            if (value == Data)
            {
                return(this);
            }

            if (value < Data)
            {
                if (LeftNode != null)
                {
                    return(LeftNode.FindRecursive(value));
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                if (RightNode != null)
                {
                    return(RightNode.FindRecursive(value));
                }
                else
                {
                    return(null);
                }
            }
        }
Exemple #2
0
        static void Main(string[] args)
        {
            InitializeTree();

            Console.WriteLine("\n\nIn-order traversal: ");
            tree.InOrderTraversal();

            Console.WriteLine("\n\nPre-order traversal: ");
            tree.PreOrderTraversal();

            Console.WriteLine("\n\nPost-order traversal: ");
            tree.PostOrderTraversal();

            Console.Write($"\n\nTree contains {18}: {tree.Contains(18)}");

            var node = tree.FindRecursive(10);

            Console.Write($"\n\nFind node recursively: {node.Data} || Count: {node.Count}");

            Console.Write($"\n\nFind node non-recursively: {tree.Find(66).Data}");

            Console.ReadLine();
        }