/*
struct TreeNode {
int val;
struct TreeNode *left;
struct TreeNode *right;
TreeNode(int x) :
val(x), left(NULL), right(NULL) {
}
};*/
class Solution {
public:
vector<int> PrintFromTopToBottom(TreeNode* root) {
vector<int> result;
if(root==NULL)
{
return result;
}
queue<TreeNode* > tmp;
tmp.push(root);
while(!tmp.empty())
{
TreeNode* temp=tmp.front();
tmp.pop();
result.push_back(temp->val);
if(temp->left!=NULL)
{
tmp.push(temp->left);
}
if(temp->right!=NULL)
{
tmp.push(temp->right);
}
}
return result;
}
};
剑指offer 从上往下打印二叉树
最新推荐文章于 2020-12-08 01:04:46 发布