using System.Collections.Generic;
public static void Main()
Console.WriteLine("Hello World");
Node successor = new Node(char.Parse("f"));
FindInOrderSuccessor(n, successor);
public static Node CreateTree(){
Node a = new Node(char.Parse("a"));
Node b = new Node(char.Parse("b"));
Node c = new Node(char.Parse("c"));
Node d = new Node(char.Parse("d"));
Node e = new Node(char.Parse("e"));
Node f = new Node(char.Parse("f"));
Node g = new Node(char.Parse("g"));
public static void FindInOrderSuccessor(Node root, Node lookingFor){
Node successor = inOrder(root, new List<Node>(),lookingFor);
Console.WriteLine("no successor");
Console.WriteLine("Successor of " + lookingFor.val.ToString() + " is " + successor.val.ToString());
successor = inOrder(root, new Stack<Node>(),lookingFor);
Console.WriteLine("no successor");
Console.WriteLine("Successor of " + lookingFor.val.ToString() + " is " + successor.val.ToString());
public static Node inOrder(Node n, List<Node> written, Node lookingFor){
Node result = inOrder(n.left, written, lookingFor);
if(result != null) return result;
Console.WriteLine(n.val.ToString());
if(written.Count > 0 && written[written.Count-1].val == lookingFor.val)
Node result = inOrder(n.right, written, lookingFor);
if(result != null)return result;
public static Node inOrder(Node n,Stack<Node> stack, Node lookingFor ){
Node result = inOrder(n.left, stack, lookingFor);
if(result != null) return result;
Console.WriteLine(n.val.ToString());
if(stack.Count>0 && stack.Peek().val == lookingFor.val)
Node result = inOrder(n.right, stack, lookingFor);
if(result != null)return result;