using System.Collections.Generic;
public static void Main()
Console.WriteLine("Hello World");
var root = BSTFromPreOrderTraversal(new int[]{10,5,1,7,40,50});
public static TreeNode BSTFromPreOrderTraversal(int[] source)
if(source == null || source.Length == 0){
var stack = new Stack<TreeNode>();
var rootNode = new TreeNode(source[0]);
for(var i = 1; i < source.Length; i++)
node = new TreeNode(val);
while (stack.Count > 0 && val > stack.Peek().Value)
public static void PreOrderTraversal(TreeNode node){
Console.WriteLine(node.Value);
PreOrderTraversal(node.Left);
PreOrderTraversal(node.Right);