void pre(Node *root, vector<int> &ans) {
if(!root) {
ans.push_back(-1);
return;
}
ans.push_back(root->data);
pre(root->left, ans);
pre(root->right, ans);
}
// Function to serialize a tree and return a list containing nodes of tree.
vector<int> serialize(Node *root) {
// Your code here
vector<int> ans;
pre(root, ans);
return ans;
}
int i = 0;
// Function to deserialize a list and construct the tree.
Node *deSerialize(vector<int> &arr) {
// Your code here
int val = arr[i];
i++;
if(val == -1) return NULL;
Node *tmp = new Node(val);
tmp->left = deSerialize(arr);
tmp->right = deSerialize(arr);
return tmp;
}