The wasBinarySearchTreePredecessor
function takes as arguments:
BST
) as a flattened list as per binary_trees.node
) to find the predecessor of.and returns the in-order predecessor of the specified node in the binary search tree.
/////////////////////////////////////////////////////////////////////////// // Copyright (C) 2013 Wizardry and Steamworks - License: GNU GPLv3 // /////////////////////////////////////////////////////////////////////////// string wasBinarySearchTreePredecessor(list BST, string node) { string left = wasBinaryTreeLeft(BST, node); if(left != "") return wasBinarySearchTreeMinimum(BST, left); string parent = wasBinaryTreeParent(BST, node); while(parent != "" && node == wasBinaryTreeLeft(BST, parent)) { node = wasBinaryTreeParent(BST, node); parent = wasBinaryTreeParent(BST, parent); } return parent; }