C++ | Serialize and De-serialize BST | a simple approach
\nclass Codec {\npublic:\n\n    string serialize(TreeNode* root) {\n        string s="";\n        if(root) {\n            s += to_string(root->val)+\'.\';\n    
```\nclass Codec {\npublic:\n\n    string serialize(TreeNode* root) {\n        string s="";\n        if(root) {\n            s += to_string(root->val)+\'.\';\n            s += serialize(root->left) + serialize(root->right);\n        }\n        return s;\n    }\n\n    TreeNode * insert(TreeNode *root, int val) {\n        if(not root)        return new TreeNode(val);\n        if(val < root->val) root->left = insert(root->left, val);\n        else                root->right = insert(root->right, val);\n        return root;\n    }\n\n    TreeNode* deserialize(string data) {\n        TreeNode *root = nullptr;\n        for(int i = 0; i<data.length(); i++) {\n            int val = 0;\n            while(data[i] != \'.\') \n                val = val*10 + data[i++] - \'0\';\n            root = insert(root, val);\n        }\n        return root;\n    }\n};\n```\n\n## Example\n```\n   2\n /   \\\n1     3\n\nSerialize using Preorded traversal. string : "2.1.3."\nDe-serialize by standard insertion in a BST process \n```\n
[]