I'm learning to code in C++.I'm trying to maintain a BST with following operations:INSERT k : insert value k into BST.LR k : left rotate node containing the value k. This is applicable to a node which has a right child. You can assume that the value k is already present in the BST.RR k : right rotate node containing the value k. This is applicable to a node which has a left child. You can assume that the value k is already present in the BST.PRE-ORDER : print BST in preorder format. However, we need to print additional data. For each node in the preorder traversal print the following triplet in constant time:(key left_subtree_size right_subtree_size)   Sample Input:5INSERT 2INSERT 1INSERT 3RR 2PRE-ORDER  Sample Output:(1 0 2)(2 0 1)(3 0 0)In the above example 5 is the number of operations we want to perform in a single run of the program.  Here's the code:  #include <bits/stdc++.h>#include <iostream>using namespace std;struct node{    int key, lsize, rsize;    node *left, *right, *parent;};class BST {private:   node* root;public:    node* new_node(int key);    /*node* parent(int key);    node** findparent(node **root, int key);*/    int node_counter(node* root);    void update_sizes(node* root);    void print();    void print(node **root);    void insert(int key);    void insert(node **root, int key);    node* srchNode(node **root, int key);    void searchNrotate(int key, string str);    void rr(node **ptr);    void lr(node **ptr);    BST() {        root = NULL;    }};int BST::node_counter(node* root){    if(root==NULL)        return 0;    return 1 + node_counter(root->left) + node_counter(root->right);}void BST::update_sizes(node* current){    if(current){    current->lsize=node_counter(current->left);    current->rsize=node_counter(current->right);    update_sizes(current->left);    update_sizes(current->right);    }}node* BST::new_node(int key){    node* temp = new node;    temp->key = key;    temp->lsize = 0;    temp->rsize = 0;    temp->left = NULL;    temp->right = NULL;    temp->parent = NULL;    return temp;}void BST::print(){    print(&root);}void BST::print(node** root){    if(*root == NULL)        return;    else{        cout<<'('<<(*root)->key<<' '<<(*root)->lsize<<' '<<(*root)->rsize<<) ;        print(&(*root)->left);        print(&(*root)->right);    }}void BST::insert(int key){   insert(&root, key);}void BST::insert(node **root, int key){   if(*root == NULL){      *root = new_node(key);   }   else{      if((*root) -> key < key){          (*root)->rsize++;          insert(&((*root) -> right), key);          (*root)->right->parent = (*root);      }      else if((*root) -> key > key){          (*root)->lsize++;          insert(&((*root) -> left), key);          (*root)->left->parent = (*root);      }   }}node* BST::srchNode(node **current, int key){    if((*current) -> key < key){        return srchNode(&((*current)->right), key);    }    else if((*current) -> key > key){        return srchNode(&((*current)->left), key);    }    else        return (*current);}void BST::searchNrotate(int key, string str){    node* ptr=root;    for(;;){        if(ptr->key > key){            ptr=ptr->left;        }        else if(ptr->key < key){            ptr=ptr->right;        }        else            break;    }    //node* ptr=srchNode(&root, key);    if(str==RR){        //rr(&ptr);        if(ptr->left){            ptr=ptr->left;            ptr->parent->left = ptr->right;            if(ptr->right)                ptr->right->parent = ptr->parent;            ptr->parent->parent = ptr;            ptr->right = ptr->parent;        }        ptr->parent = NULL;        root = ptr;    }    else if(str==LR){        //lr(&ptr);        if(ptr->right){            ptr=ptr->right;            ptr->parent->right = ptr->left;            if(ptr->left)                ptr->left->parent = ptr->parent;            ptr->parent->parent = ptr;            ptr->left = ptr->parent;        }        ptr->parent = NULL;        root = ptr;    }    update_sizes(root);}int main() {    int T, N;    string s,str;    cin >> T;    BST bst;    for(int t=0; t<T; t++){        cin >> s;        if(s == INSERT){            cin >> N;            bst.insert(N);        }        if(s==RR){            cin >> N; str=RR;            bst.searchNrotate(N,str);        }        if(s==LR){            cin >> N; str=LR;            bst.searchNrotate(N,str);        }        if(s==PRE-ORDER){            bst.print(); cout<<endl;        }    }    return 0;}I'm trying hard to figure out what's wrong with this code. This code inserts and prints properly as per my observations but it doesn't perform the rotation operation correctly.Can anyone tell me where I'm doing things wrong. Any help is appreciable. Thanks in advance.
Maintenance of a Binary Search Tree (BST) on integers
c++;tree