private int maxDiff(Nodi root, int k) { min_diff = 9999999; min_diff_key = -1; maxDiffUtil(root, k); return(min_diff); }
public void Main() { Nodi root = new Nodi(9); root.Left = new Nodi(4); root.Right = new Nodi(17); root.Left.Left = new Nodi(3); root.Left.Right = new Nodi(6); root.Left.Right.Left = new Nodi(5); root.Left.Right.Right = new Nodi(7); root.Right.Right = new Nodi(22); root.Right.Right.Left = new Nodi(20); Console.WriteLine($"k=4 result={maxDiff(root, 4)} expected=17"); Console.WriteLine($"k=18 result={maxDiff(root, 18)} expected=17"); Console.WriteLine($"k=12 result={maxDiff(root, 12)} expected=9"); }