public static void Main()
root.right = new Node(12);
root.left.left = new Node(2);
root.left.right = new Node(6);
root.left.right.left = new Node(5);
root.left.right.right = new Node(7);
root.right.left = new Node(10);
root.right.right = new Node(14);
Console.WriteLine(FindCeilingFloor(root, 4));
public static Node FindTarget(Node root, int target) {
if (root.value < target) {
return FindTarget(root.right, target);
} else if (root.value > target) {
return FindTarget(root.left, target);
public static (int, int) FindCeilingFloor(Node root, int target) {
Node targetRoot = FindTarget(root, target);
Node floor = FindFloor(targetRoot);
Node ceiling = FindCeiling(targetRoot);
return (floor.value, ceiling.value);
public static Node FindFloor(Node root) {
while (curr.right != null) {
public static Node FindCeiling(Node root) {
while (curr.left != null) {