从上往下打印二叉树

/*
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> res;
        if(root==NULL)
            return res;
        deque<TreeNode*>prin;
        prin.push_back(root);
        while(prin.size())
            {
            TreeNode *tmp=prin.front();
            prin.pop_front();
            res.push_back(tmp->val);
            if(tmp->left)
                prin.push_back(tmp->left);
            if(tmp->right)
                prin.push_back(tmp->right);
            
        }
        return res;
    }
};
原文地址:https://www.cnblogs.com/daocaorenblog/p/5356724.html