Update bst successor solution (#107)

Update bst successor solution
This commit is contained in:
Donne Martin 2016-10-25 06:22:34 -04:00 committed by GitHub
parent bd89e83b65
commit cf337334a5

View File

@ -115,20 +115,23 @@
"\n",
" def get_next(self, node):\n",
" if node is None:\n",
" raise Exception('Invalid input node')\n",
" raise TypeError('node cannot be None')\n",
" if node.right is not None:\n",
" return self._left_most(node.right)\n",
" else:\n",
" return self._next_ancestor(node)\n",
"\n",
" def _left_most(self, node):\n",
" if node.left is not None:\n",
" return self._left_most(node.left)\n",
" else:\n",
" return node.data\n",
"\n",
" def _next_ancestor(self, node):\n",
" if node.parent is not None:\n",
" if node.parent.data > node.data:\n",
" return node.parent.data\n",
" else:\n",
" return self._next_ancestor(node.parent)\n",
" # We reached the root, the original input node\n",
" # must be the largest element in the tree.\n",