GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — CodingInterview/Solution8.java at master · legolas007/CodingInterview Expand file tree/ Copy pathSolution8.javaMore file actions 29 lines (28 loc) · 987 Bytes / Copy pathSolution8.javaFile metadata and controls29 lines (28 loc) · 987 Bytes 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. |