/* 层次遍历 */ class Solution { public: vector<int> PrintFromTopToBottom(TreeNode* root) { vector<int> vt; if(!root)return vt;//push()进去的不能为空 queue<TreeNode*> q; q.push(root); while(!q.empty()){ TreeNode* tmp=q.front();q.pop(); vt.push_back(tmp->val); if(tmp->left)q.push(tmp->left); if(tmp->right)q.push(tmp->right); } return vt; } };