Script Name: Binary Search Tree
Script Description Allows programmers to implement binary search trees.
Author: iDanteCompile Test: PassedCore Version: 2.6.5
Hosted by: Soldat Central - http://soldatcentral.com/Full Description:This script provides scripters with the means to create and play with binary search trees in their most primitive form (not self-balancing, pretty slow compared to other implementations). This was mostly written because I needed to figure out how these silly things work.
Not sure how useful it is, if at all, but I thought I'd post it.
Function list:function BST_Create(values: array of variant): tBinarySearchTree;Creates a binary search tree out of the specified values.
procedure BST_Balance(var tree: tBinarySearchTree);Balances the tree. This is a slow operation, so don't go balance-happy. On the flipside, it is necessary for the tree to be balanced every now and then or add/deletes will get slow.
function BST_Traverse(var tree: tBinarySearchTree): array of variant;Returns a sorted (ascending) list of all values in the tree. This is a fast operation.
procedure BST_Insert(var tree: tBinarySearchTree; val: variant);Inserts the value into the tree. Not much more to say. Duplicates are ignored.
procedure BST_Delete(var tree: tBinarySearchTree; val: variant);Deletes the value from the tree.
function BST_Search(var tree: tBinarySearchTree; val: variant): boolean;Returns whether the value is in the tree or not. Fast (O(logn)) and delicious