标签:tom pre logs top nod nbsp blog style ott
/* 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> result; if (root == NULL) return result; Q.push(root); while (!Q.empty()) { TreeNode* p = Q.front(); result.push_back(p->val); Q.pop(); if (p->left != NULL) { Q.push(p->left); } if (p->right != NULL) { Q.push(p->right); } } return result; } };
标签:tom pre logs top nod nbsp blog style ott
原文地址:http://www.cnblogs.com/159269lzm/p/7296169.html