从上往下打印出二叉树的每个节点,同层节点从左至右打印。
class Solution {public: vector PrintFromTopToBottom(TreeNode* root) { vector vec; if(!root) return vec; queueque; TreeNode* temp; que.push(root); while(que.size()) { temp = que.front(); vec.push_back(temp->val); que.pop(); if(temp->left) que.push(temp->left); if(temp->right) que.push(temp->right); } return vec; }};