BT & BST C++ Solution: Preorder, Comma seperated with comments
(1) Binary Search Tree\n\nclass Codec {\npublic:\n    void serializehelper(TreeNode* root, string& s){\n        if(root==nullptr) return;\n        \n        s+=
(1) Binary Search Tree\n```\nclass Codec {\npublic:\n    void serializehelper(TreeNode* root, string& s){\n        if(root==nullptr) return;\n        \n        s+=to_string(root->val) + ","; // \',\' for seperating each value\n        serializehelper(root->left, s);\n        serializehelper(root->right, s);\n    }\n    \n    string serialize(TreeNode* root) {\n        if(root==nullptr) return "";\n        \n        string s="";\n        serializehelper(root, s);\n        \n        return s;\n    }\n    \n    int convertStringtoInt(string& data, int& pos){ // Find \',\' and return value\n        pos=data.find(\',\');\n        int value=stoi(data.substr(0, pos));\n        return value;\n    }\n    \n    TreeNode* deserializehelper(string& data, int min, int max) {\n        if(data.size()==0) return nullptr; // If no more elements, return nullptr\n        \n        int pos=0;\n        int value = convertStringtoInt(data, pos); // Find new value and position of \',\'\n        if (value < min || value > max) return nullptr; // Is new value in given range\n        \n        TreeNode* tnode = new TreeNode(value); \n        data=data.substr(pos+1); // Update only when in range\n        \n        tnode->left=deserializehelper(data, min, tnode->val); // Branch off to left & right subtree with given ranges\n        tnode->right=deserializehelper(data, tnode->val, max);\n        return tnode;\n    }\n    \n    TreeNode* deserialize(string data) {\n        if(data=="") return nullptr;\n        return deserializehelper(data, INT_MIN, INT_MAX);\n    }\n};\n```\n\n(2) Binary Tree\n```\nclass Codec {\npublic:\n    string serialize(TreeNode* root) {\n        if(root==nullptr) return "X";\n        \n        return to_string(root->val) + "," + serialize(root->left) + "," + serialize(root->right); // to_string\n    }\n    int convertStringtoInt(string& data){\n        int pos=data.find(\',\');\n        int value=stoi(data.substr(0, pos));\n        data=data.substr(pos+1);\n        return value;\n    }\n    TreeNode* deserializehelper(string& data) { // data is updated, hence by reference\n        if(data[0]==\'X\'){\n            if(data.size()>1)\n                data=data.substr(2);  // keep removing data \n            return nullptr;\n        }\n        \n        TreeNode* tnode = new TreeNode(convertStringtoInt(data));  // covert data using stoi\n        tnode->left=deserializehelper(data);\n        tnode->right=deserializehelper(data);\n        return tnode;\n    }\n    TreeNode* deserialize(string data) {\n        return deserializehelper(data);\n    }\n};\n```\nI appreciate your upvote !!
['Binary Search Tree', 'C', 'C++']