把二叉树打印成多行

 1 class Solution {
 2 public:
 3         vector<vector<int> > Print(TreeNode* pRoot) {
 4         vector<vector<int>> res;
 5         if(pRoot == NULL)
 6             return res;
 7         queue<TreeNode*> node;
 8         node.push(pRoot);
 9         int prin = 1;
10         while(prin!=0)
11         {
12             vector<int> lev;
13             int next_prin = 0;
14             while(prin !=0)
15             {
16                 TreeNode *p = node.front();
17                 node.pop();
18                 --prin;
19                 lev.push_back(p->val);
20                 if(p->left)
21                 {
22                   node.push(p->left);
23                   next_prin++;
24                 }
25                 if(p->right)
26                 {
27                     node.push(p->right);
28                     next_prin++;
29                 }
30             }
31             prin = next_prin;
32             res.push_back(lev);
33             
34         }
35         return res;
36         }
37     
38 };
原文地址:https://www.cnblogs.com/daocaorenblog/p/5463456.html