C++ simple level-order traversal
\n    // Encodes a tree to a single string.\n    string serialize(TreeNode root) {\n        if(root==NULL)\n            return "";\n        string s="";\n      
\n    // Encodes a tree to a single string.\n    string serialize(TreeNode* root) {\n        if(root==NULL)\n            return "";\n        string s="";\n        \n        queue<TreeNode*> q;\n        q.push(root);\n        while(!q.empty())\n        {\n            TreeNode* temp=q.front();\n            q.pop();\n            \n            if(temp==NULL)\n            {\n                s.append("#,");\n            }\n            else\n            {\n                s.append(to_string(temp->val)+\',\');\n            }\n            \n            if(temp!=NULL)\n            {\n                q.push(temp->left);\n                q.push(temp->right);\n            }\n        }\n\n        return s;\n    }\n\n    // Decodes your encoded data to tree.\n    TreeNode* deserialize(string data) {\n        if(data.length()==0)\n            return NULL;\n        \n        stringstream s(data);\n        string str;\n        getline(s,str,\',\');\n        TreeNode* root=new TreeNode(stoi(str));\n        queue<TreeNode*> q;\n        q.push(root);\n        \n        while(!q.empty())\n        {\n            TreeNode* temp=q.front();\n            q.pop();\n            \n            getline(s,str,\',\');\n            if(str=="#")\n            {\n                temp->left=NULL;\n            }\n            else\n            {\n                TreeNode* leftNode=new TreeNode(stoi(str));\n                temp->left=leftNode;\n                q.push(leftNode);\n            }\n            \n            getline(s,str,\',\');\n            if(str=="#")\n            {\n                temp->right=NULL;\n            }\n            else\n            {\n                TreeNode* rightNode=new TreeNode(stoi(str));\n                temp->right=rightNode;\n                q.push(rightNode);\n            }\n        }\n        \n        return root;\n    }\n\n
['String', 'Queue']