// BST. class Node { Node parent; Node left; Node right; } Node min(Node node) { if (node == null) return null; while(node.left != null) node = node.left; return node; } // in-order ? Node next(Node node) { if (node == null) return null; if (node.right != null) { Node toReturn = node.right; while (toReturn.left != null) { toReturn = toReturn.left; } return toReturn; } while( node != null) { if (node == node.parent.left) return node.parent; else node = node.parent; } return null; }
时间: 2024-10-21 03:01:49