target and set it to 5findFloor and findCeil that find floor and ceil values in the BST for targetFloor: X and Ceil: Ytarget and set it to 5findFloor and findCeil that find floor and ceil values in the BST for targetFloor: X and Ceil: YNode with int data, Node* left, and Node* right. Then write a function insertNode that takes Node* root and int val and inserts a new node with val into the BST. Finally, create a Node* root and insert these values in order: 8, 4, 12, 2, 6, 10, 14.Start by defining the Node structure with data and pointers to left and right children. Then write a recursive insert function that places values correctly in the BST. Finally, create the root pointer and insert the given values one by one.
target and set it to 5 inside main() after the BST is created.Just add a line inside main() to create an integer variable named target and assign it the value 5.
int findFloor(Node* root, int target) and int findCeil(Node* root, int target). Each function should return the floor or ceil value for target in the BST. Use the BST property to traverse efficiently. Return -1 if no floor or ceil exists.Use a loop to traverse the BST. For floor, move left if current node is greater than target, else update floor and move right. For ceil, move right if current node is less than target, else update ceil and move left. Return -1 if no suitable value found.
main(), after calling findFloor and findCeil, print the results exactly as: Floor: X and Ceil: Y where X and Y are the floor and ceil values found.Use cout to print the floor and ceil values with the exact format: Floor: X and Ceil: Y.
floor of a value in a Binary Search Tree (BST) represent?Node? 10
/ \
5 15
/ \
12 20
int floorBST(Node* root, int val) {
if (!root) return -1;
if (root->data == val) return root->data;
if (root->data > val) return floorBST(root->left, val);
int floorRight = floorBST(root->right, val);
return (floorRight != -1 && floorRight <= val) ? floorRight : root->data;
}
What is the bug?Pass the test and this pattern moves unknown