GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — CodingInterview/Solution8.java at master · legolas007/CodingInterview

Expand file tree

/

Solution8.java

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
29 lines (28 loc) · 987 Bytes
/

Solution8.java

Copy path

File metadata and controls

29 lines (28 loc) · 987 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package com.usher.algorithm.offer;
/**
* @Author: Usher
* @Description:
*
* 二叉树的下一个节点:找出中序遍历的下一个节点,树中的结点不仅包含左右子结点,同时包含指向父结点的指针。
* 1,如果一个节点的右子树不为空,那么该节点的下一个节点是右子树的最左节点
* 2,否则向上找第一个左链接指向的树包含该节点的祖先节点
*/
public class Solution8 {
public TreeLinkNode GetNext(TreeLinkNode pNode){
if (pNode.right != null){
TreeLinkNode node = pNode.right;
while (node.left != null){
node = node.left;
}
return node;
}else {
while (pNode.next != null){//父亲节点
TreeLinkNode parent = pNode.next;
if (parent.left == pNode)
return parent;
pNode = pNode.next;
}
}
return null;
}
}
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.