Please convert the code inC language
#include using namespace std;class Node{ public: int data; //value Node *left; //pointer to left child Node *right; //pointer to right child};// creating new nodeNode* newnode(int data){ Node* node = (Node*)malloc(sizeof(Node)); node->data = data; node->left = NULL; node->right = NULL; return(node);}Node* LCA(Node *root, int n1, int n2){while(true){ if((root->data>=n1 && root->data<=n2)||(root->data<=n1 &&="" root-="">data>=n2)) return root; if(n1data) root=root->left; else root=root->right; }}int main(){ cout<"tree is="" built="" as="" per="" 1st="">"tree> Node *root=newnode(8); root->left= newnode(4); root->right= newnode(10); root->right->right=newnode(11); root->right->left=newnode(9); root->left->left=newnode(3); root->left->right=newnode(5); int n1=9, n2=11; cout<"lowest common="" ancestor="" of="">"lowest><><" &="">"><> cout<">">data<> return 0;}Output:Extracted text: tree is built as per 1st example Lowest common ancestor of 9 & 11 is:10=n1>=n2)||(root->
class Node{ public: int data; //value Node *left; //pointer to left child Node *right; //pointer to right child};
// creating new nodeNode* newnode(int data){ Node* node = (Node*)malloc(sizeof(Node)); node->data = data; node->left = NULL; node->right = NULL; return(node);}
Node* LCA(Node *root, int n1, int n2){while(true){ if((root->data>=n1 && root->data<=n2)||(root->data<=n1 &&="" root-="">data>=n2)) return root; if(n1data) root=root->left; else root=root->right; }}int main(){ cout<"tree is="" built="" as="" per="" 1st="">"tree> Node *root=newnode(8); root->left= newnode(4); root->right= newnode(10); root->right->right=newnode(11); root->right->left=newnode(9); root->left->left=newnode(3); root->left->right=newnode(5); int n1=9, n2=11; cout<"lowest common="" ancestor="" of="">"lowest><><" &="">"><> cout<">">data<> return 0;}Output:Extracted text: tree is built as per 1st example Lowest common ancestor of 9 & 11 is:10=n1>=n2)||(root->
int main(){ cout<"tree is="" built="" as="" per="" 1st="">"tree> Node *root=newnode(8); root->left= newnode(4); root->right= newnode(10); root->right->right=newnode(11); root->right->left=newnode(9); root->left->left=newnode(3); root->left->right=newnode(5);
int n1=9, n2=11;
cout<"lowest common="" ancestor="" of="">"lowest><><" &="">"><> cout<">">data<> return 0;}Output:Extracted text: tree is built as per 1st example Lowest common ancestor of 9 & 11 is:10
Output:
Extracted text: tree is built as per 1st example Lowest common ancestor of 9 & 11 is:10
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here