Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void dfs( Node *root,vector<int>&list)
- {
- if( root==NULL )
- {
- list.push_back(-1);
- return;
- }
- list.push_back( root->data );
- dfs( root->left );
- dfs( root->right );
- }
- vector<int> serialize(Node *root)
- {
- vector<int>list;
- dfs( root,list );
- //5 3 -1 -1 2 6 -1 -1 1 -1 -1
- return list;
- }
- void totree( Node* root,int &pos,vector<int>&list )
- {
- if( list[pos]==-1 )
- {
- pos++;
- return;
- }
- root= new Node();
- root->data=list[pos];
- pos++;
- totree( root->left,pos,list );
- totree( root->right,pos,list );
- }
- Node *deserialize(vector<int> list)
- {
- Node *root;
- root=NULL;
- //5 3 -1 -1 2 6 -1 -1 1 -1 -1
- totree( root,0,list );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement