Please convert the code in C 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...


Please convert the code in
C 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 node
Node* 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="">
    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=""><><" &=""><>
    cout<">data<>

    return 0;
}




Output:



tree is built as per 1st example<br>Lowest common ancestor of 9 & 11 is:10<br>

Extracted text: tree is built as per 1st example Lowest common ancestor of 9 & 11 is:10

Jun 05, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here