从上到下按层打印二叉树,同一层的节点按从左到右的顺序打印,每一层打印到一行。
例如:
给定二叉树: [3,9,20,null,null,15,7]
返回其层次遍历结果:
[
[3],
[9,20],
[15,7]
]
/** * Definition for a binary tree node.
* struct TreeNode {
* * int val;
* * struct TreeNode *left;
* * struct TreeNode *right;
* * };
* */
* /** * Return an array of arrays of size
* *returnSize.
* * The sizes of the arrays are returned as
* *returnColumnSizes array.
* * Note: Both returned array and
* *columnSizes array must be malloced, assume caller calls free().
* */
#define MAXSIZE 10000
int** levelOrder(struct TreeNode* root, int* returnSize, int** returnColumnSizes)
{
if(NULL == root