/* function TreeNode(x) {
    this.val = x;
    this.left = null;
    this.right = null;
} */
function KthNode(pRoot, k)
{
    // write code here
    if(!pRoot || !k) {
        return null;
    }
    let res = [];
    let tempRes = [];
    tempRes.push(pRoot);
    while(tempRes.length) {
        let item = tempRes.shift();
        res.push(item);
        if(item.left) {
            tempRes.push(item.left);
        }
        if(item.right) {
            tempRes.push(item.right);
        }
    }
    res.sort((a, b) => a.val - b.val);
    return res[k - 1];
}
module.exports = {
    KthNode : KthNode
};