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