c++
二叉树的下一个结点
http://www.nowcoder.com/questionTerminal/9023a0c988684a53960365b889ceaf5e
/* 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 == NULL) return NULL; if (pNode->right) { TreeLinkNode* p = pNode->right; while(p->left) p = p->left; return p; } else if (pNode->next){ TreeLinkNode* cur = pNode; TreeLinkNode* parent = pNode->next; while(parent && cur == parent->right) { cur = parent; parent = cur->next; } return parent; } else { return NULL; } } };