C++ | Queue and Preorder
\nclass Codec {\npublic:\n    // Encodes a tree to a single string.\n     string serialize(TreeNode* root) {\n        if(!root) return "x,";\n        string l=s
```\nclass Codec {\npublic:\n    // Encodes a tree to a single string.\n     string serialize(TreeNode* root) {\n        if(!root) return "x,";\n        string l=serialize(root->left);\n        string r=serialize(root->right);\n        return to_string(root->val)+","+l+r;\n    }\n    \n    TreeNode* deserializeHelper(queue<string>& q) {\n        string ch=q.front();\n        q.pop();\n        if(ch=="x") return NULL;\n        TreeNode* root=new TreeNode(stoi(ch));\n        root->left=deserializeHelper(q);\n        root->right=deserializeHelper(q);\n        return root;       \n    }\n\n    // Decodes your encoded data to tree.\n    TreeNode* deserialize(string data) {\n        stringstream ss(data);\n        queue<string> q;\n        cout << data<< endl;\n        while (ss.good()) {\n            string str;\n            getline(ss, str,\',\');\n            q.push(str);\n        }\n        return deserializeHelper(q);\n    }\n};\n```
['Queue', 'C']