using System.Collections.Generic;
public int Value { get; set; }
public Node Left { get; set; }
public Node Right { get; set; }
public Node(int value, Node left, Node right)
public class BinarySearchTree
public static bool Contains(Node root, int value)
List<int> treeValues = new List<int>();
return FlattenTree(root, ref treeValues).Contains(value);
public static void Main(string[] args)
Node n1 = new Node(1, null, null);
Node n3 = new Node(3, null, null);
Node n2 = new Node(2, n1, n3);
Console.WriteLine(Contains(n2, 3));
private static List<int> FlattenTree(Node root, ref List<int> treeValues)
if (root == null) return treeValues;
Console.WriteLine(root.Value);
treeValues.Add(root.Value);
FlattenTree(root.Left, ref treeValues);
FlattenTree(root.Right, ref treeValues);