@LIUHUAN
2019-05-05T23:09:49.000000Z
字数 520
阅读 840
algorithm
struct TreeNode {
int val;
TreeNode *left;
TreeNode *right;
TreeNode(int x) : val(x), left(NULL), right(NULL) {}
};
vector<int> tree_level_order_traverse(TreeNode* root) {
if(root == nullptr)
return {};
queue<TreeNode*> que;
que.push(root);
vector<int> res;
while(!que.empty()) {
int size = que.size();
for(int i =0 ;i < size; i++) {
TreeNode *n = que.front();
que.pop();
res.push_back(n->val);
if(n->left)
que.push(n->left);
if(n->right)
que.push(n->right);
}
}
return res;
}