예제 #1
0
 void deserializeHelper(string data, int &start,  TreeNode *&root) {
     int num;
     if (!getNumber(data, start, num)) {
         root = nullptr;
         return;
     }
     else {
         root = new TreeNode(num);
         deserializeHelper(data, start, root->left);
         deserializeHelper(data, start, root->right);
     }
 }
예제 #2
0
 TreeNode* deserializeHelper(istringstream& in) {
   string val;
   in >> val;
   if (val == "#") {
     return NULL;
   } else {
     TreeNode* root = new TreeNode(stoi(val));
     root->left = deserializeHelper(in);
     root->right = deserializeHelper(in);
     return root;
   }
 }
 void deserializeHelper(TreeNode *&root, int &start, const string &data)
 {
     int num;
     if (!getNumber(data, start, num))
     {
         root = nullptr;
         return;
     }
     root = new TreeNode(num);
     deserializeHelper(root->left, start, data);
     deserializeHelper(root->right, start, data);
 }
 /**
  * This method will be invoked second, the argument data is what exactly
  * you serialized at method "serialize", that means the data is not given by
  * system, it's given by your own serialize method. So the format of data is
  * designed by yourself, and deserialize it here as you serialize it in 
  * "serialize" method.
  */
 TreeNode *deserialize(string data) {
     // write your code here
     int start = 0;
     TreeNode *root;
     deserializeHelper(root, start, data);
     return root;
 }
 NestedInteger deserialize(string s) {
     if (s == "")
         return NestedInteger();
     istringstream in(s);
     return deserializeHelper(in);
 }
예제 #6
0
 /**
  * This method will be invoked second, the argument data is what exactly
  * you serialized at method "serialize", that means the data is not given by
  * system, it's given by your own serialize method. So the format of data is
  * designed by yourself, and deserialize it here as you serialize it in
  * "serialize" method.
  */
 TreeNode *deserialize(string data) {
     TreeNode *root = nullptr;
     int start = 0;
     deserializeHelper(data, start, root);
     return root;
 }
 // Decodes your encoded data to tree.
 TreeNode* deserialize(string data) {
     istringstream in(data);
     return deserializeHelper(in);
 }