Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions 2 May Serialize and deserialize a binary tree
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
class Solution
{
public:
//Function to serialize a tree and return a list containing nodes of tree.
void ino(Node *root, vector<int> &v){
if(root==NULL) return ;
ino(root->left,v);
v.push_back(root->data);
ino(root->right,v);
}

vector<int> serialize(Node *root)
{
vector<int>v;
ino(root,v);


return v;
}

Node * deSel(vector<int> &A,int &ind){
if(ind >= A.size() || A[ind] == -1) return NULL;

Node *root = new Node(A[ind++]);
root->right = deSel(A,ind);
root->left = deSel(A,ind);


return root;
}

Node * deSerialize(vector<int> &A)
{
//Your code here
int ind = 0;
return deSel(A,ind);
}

};