-
Notifications
You must be signed in to change notification settings - Fork 0
/
treePrint.c
33 lines (28 loc) · 851 Bytes
/
treePrint.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
class Solution {
public:
vector<vector<int> > Print(TreeNode* pRoot) {
vector<vector<int> >array;
if(pRoot == NULL)
return array;
queue<TreeNode *>q;
q.push(pRoot);
while(!q.empty())
{
int i = 0;
vector<int>a;
int hight = q.size();
while(i<hight)
{
a.push_back(q.front()->val);
if(q.front()->left!=NULL)
q.push(q.front()->left);
if(q.front()->right != NULL)
q.push(q.front()->right);
q.pop();
i++;
}
array.push_back(a);
}
return array;
}
};