#include using namespace std; struct TreeNode { int data; TreeNode* right; TreeNode* left; TreeNode(int data) { this->data = data; this->left = NULL; this->right = NULL; }}; TreeNode* insertNode(int data, TreeNode* root){ if (root == NULL) { TreeNode* node = new TreeNode(data); return node; } else if (data > root->data) { root->right = insertNode( data, root->right); } else if (data data) { root->left = insertNode( data, root->left); } return root;} int countNodes(TreeNode* root){ if (root == NULL) return 0; else return countNodes(root->left) + countNodes(root->right) + 1;} TreeNode* toWaveList(TreeNode* root){ int […]

Continue ReadingGiven a Binary Search Tree, the task is to create a wave array from the given Binary Search Tree. An array arr[0..n-1] is called a wave array if arr[0] >= arr[1] = arr[3] = …Examples:Input: Output: 4 2 8 6 12 10 14Explanation: The above mentioned array {4, 2, 8, 6, 12, 10, 14} is […]

Continue Reading#include using namespace std;class Node {public: int val; Node *left, *right;};Node* newNode(int item){ Node* temp = new Node(); temp->val = item; temp->left = temp->right = NULL; return temp;}int sum = 0;int rangeSumBST(Node* root, int low, int high){ if (root == NULL) return 0; queue q; q.push(root); while (q.empty() == false) { Node* curr = q.front(); q.pop(); if (curr->val >= low && curr->val val; } if (curr->left != NULL && curr->val > low) q.push(curr->left); if (curr->right != […]

Continue Reading