From e1a2904cfe35e4dd2e443811ca6763f46c3d1adb Mon Sep 17 00:00:00 2001 From: marina <138340846+bt3gl-cryptographer@users.noreply.github.com> Date: Thu, 3 Aug 2023 13:56:53 -0700 Subject: [PATCH] Create bst_pre_sucessor.py --- trees/bst_pre_sucessor.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 trees/bst_pre_sucessor.py diff --git a/trees/bst_pre_sucessor.py b/trees/bst_pre_sucessor.py new file mode 100644 index 0000000..db3bcc7 --- /dev/null +++ b/trees/bst_pre_sucessor.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# author: bt3gl + + +def successor(root): + + root = root.right + + while root.left: + root = root.left + + return root + + +def predecessor(root): + + root = root.left + + while root.right: + root = root.right + + return root