Construct a Binary Tree from String with bracket representation | Set 2

  #include using namespace std;  struct Node {    Node* left;    Node* right;    int data;              Node(int element)    {        data = element;        this->left = nullptr;        this->right = nullptr;    }};  void preorder(Node* root){    if (!root)        return;      cout data left);    preorder(root->right);}  Node* constructTree(string s){          Node* root = new Node(s[0] – ‘0’);              stack stk;          for (int i = 1; i < s.length(); i++) {                  if (s[i] == '(') {                          stk.push(root);        }                  else if (s[i] == ')') {                                      root = stk.top();                          stk.pop();        }                  else {                                                  if (root->left == nullptr) {                  Node* left = new Node(s[i] – ‘0’);                root->left = left;                root = root->left;            }                                                  else if (root->right == nullptr) {                  Node* right = new Node(s[i] – ‘0’);                root->right = right;                root = root->right;            }        }    }          return root;}  int main(){        string s = “4(2(3)(1))(6(5))”;          Node* root = constructTree(s);    preorder(root);      return 0;}