/* function TreeNode(x) {
    this.val = x;
    this.left = null;
    this.right = null;
} */
function Print(pRoot)
{
    // write code here
    if(pRoot == null) return [];
    const queue=[pRoot];
    let depth=0;
    const res=[];
    
    while(queue.length>0){
        let level=[];
        let size=queue.length;
        while(size--){
            const cur=queue.shift();
            depth % 2 === 0 ?level.push(cur.val):level.unshift(cur.val);
            if(cur.left){
                queue.push(cur.left);
            }
            
            if(cur.right){
                queue.push(cur.right);
            }
        }
        
        depth++;
        
        res.push(level);
    }
    
    return res;
}
module.exports = {
    Print : Print
};