首页 > 其他 > 详细

8. 二叉树的下一个结点

时间:2021-03-28 12:54:59      阅读:22      评论:0      收藏:0      [点我收藏+]
/*
struct TreeLinkNode {
    int val;
    struct TreeLinkNode *left;
    struct TreeLinkNode *right;
    struct TreeLinkNode *next;
    TreeLinkNode(int x) :val(x), left(NULL), right(NULL), next(NULL) {
        
    }
};
*/
class Solution {
public:
    TreeLinkNode* GetNext(TreeLinkNode* pNode) {
        if(pNode->right){
            pNode = pNode->right;
            while(pNode->left != nullptr){
                pNode = pNode->left;
            }
            return pNode;
        }else{
            while(pNode->next){
                if(pNode == pNode->next->left){
                    return pNode->next;
                }
                pNode = pNode->next;
            }
            return nullptr;
        }
        
    }
};

8. 二叉树的下一个结点

原文:https://www.cnblogs.com/N3ptuner/p/14588201.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!