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