C++ simple and clean PreOrder traversal solution
\nclass Codec {\npublic:\n\n    // Encodes a tree to a single string.\n    string serialize(TreeNode* root) {\n        return encode(root);\n    }\n\n    // Dec
```\nclass Codec {\npublic:\n\n    // Encodes a tree to a single string.\n    string serialize(TreeNode* root) {\n        return encode(root);\n    }\n\n    // Decodes your encoded data to tree.\n    TreeNode* deserialize(string data) {\n        stringstream ss(data);\n        string item;\n        TreeNode* root = NULL;\n        \n        while (getline (ss, item, \'-\')) \n            root = insert(root, stoi(item));\n\n        return root;\n    }\n    \nprivate:\n    string encode(TreeNode* root) {\n        if (!root)\n            return "";\n        return to_string(root->val) + "-" + encode(root->left)+encode(root->right);\n    }\n    \n    TreeNode* insert(TreeNode* root, int val) {\n        if (root == NULL) {\n\t\t\tTreeNode* temp=new TreeNode(val);\n\t\t\treturn temp;\n\t\t}\n    \n\t\tif (val<=root->val)\n\t\t\troot->left=insert(root->left,val);\n    \n\t\telse\n\t\t\troot->right=insert(root->right,val);\n    \n\t\treturn root;\n    }\n};\n```\n**Like it? please upvote...**
['C']