※ offer wins the series 50: sequence of binary tree

First is what is serialized binary tree, it is to convert into a string of binary sequence. Deserialization is configured as a string of a binary sequence.

I do not really understand the question, why write

 1 class Solution {
 2 public:
 3     vector<int> aux;
 4     void treetovec(TreeNode * root)
 5     {
 6         if (!root)//空节点
 7         {
 8             aux.push_back(0xFFFFFFFF);
 9         }
10         else {
11             aux.push_back(root->val);
12             treetovec(root->left);//前序遍历
13             treetovec(root->right);
 14          }
 15          
16      }
 . 17      the TreeNode vectotree * ( int * & C)
 18 is      {
 . 19          IF (* C == 0xFFFFFFFF ) // null node 
20 is          {
 21 is              C ++ ;
 22 is              return NULL;
 23 is          }
 24          the else {
 25              the TreeNode * = CUR new new TreeNode (* c); // this sentence what is?
26                                               // use a variable of type int to initialize a TreeNode 
27              c ++;
28             cur->left = vectotree(c);
29             cur->right = vectotree(c);
30             return cur;
31         }
32     }
33     char* Serialize(TreeNode *root) //序列化二叉树
34     {
35         treetovec(root);
36         int len = aux.size();
37         int *res = new int[len];
38         for (int i = 0; i < len; i++)
39             res[i] =AUX [I];
 40          return ( char * ) RES;
 41 is  
42 is      }
 43 is      the TreeNode the Deserialize * ( char * STR) // deserialize binary tree 
44 is      {
 45          int * C = ( int * ) STR;
 46 is          return vectotree (C) ;
 47      }
 48 };

 

Guess you like

Origin www.cnblogs.com/neverland0718/p/11265752.html