标签:
1 /* 2 struct TreeNode { 3 int val; 4 struct TreeNode *left; 5 struct TreeNode *right; 6 TreeNode(int x) : 7 val(x), left(NULL), right(NULL) { 8 } 9 };*/ 10 class Solution { 11 public: 12 vector<int> PrintFromTopToBottom(TreeNode *root) { 13 queue <TreeNode *> que; 14 vector<int> res; 15 if(root==NULL) 16 return res; 17 que.push(root); 18 while(que.size()!=0) 19 { 20 TreeNode *pNode=que.front(); 21 que.pop(); 22 res.push_back(pNode->val); 23 24 if(pNode->left!=NULL) 25 que.push(pNode->left); 26 if(pNode->right!=NULL) 27 que.push(pNode->right); 28 } 29 return res; 30 } 31 };
标签:
原文地址:http://www.cnblogs.com/lou424/p/5032459.html