static void SearchRecursively(int key, Node rootNode) { Console.WriteLine($"Search for {key} recursively..."); var founded = rootNode.Find(key)?.Key; Console.WriteLine($"Found: {founded}"); }
public Node Find(int data) { if (root != null) { return(root.Find(data)); } else { return(null); } }
//To find the a specific/given node public Node findVal(int data) { //if the root is not null then we call the find method on the root if (root != null) { // call node method Find return(root.Find(data)); } else {//the root is null so we return null, nothing to find return(null); } }
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(); }