标签:
/* 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) { queue<TreeNode *> q; vector<int> s; if(root==NULL) return s; q.push(root); while(!q.empty()){ TreeNode *p=q.front(); s.push_back(p->val); q.pop(); if(p->left) q.push(p->left); if(p->right) q.push(p->right); } return s; } };
标签:
原文地址:http://www.cnblogs.com/cancangood/p/4934444.html