Author Topic: Binary Search Trees  (Read 1228 times)

0 Members and 2 Guests are viewing this topic.

Offline iDante

  • Veteran
  • *****
  • Posts: 1967
Binary Search Trees
« on: October 26, 2009, 11:14:42 pm »
Script Name: Binary Search Tree
Script Description Allows programmers to implement binary search trees.
Author: iDante
Compile Test: Passed
Core 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 :)



(Size 1.49 KB)
- http://soldatcentral.com/index.php?page=script&f=146 -


** Script hosted by Soldat Central! Please visit the author's script page and Rate this script **

Offline CurryWurst

  • Camper
  • ***
  • Posts: 265
    • Soldat Global Account System
Re: Binary Search Trees
« Reply #1 on: October 27, 2009, 09:08:39 am »
I very much appreciate this brilliant script. It will be pretty useful in my MySSQL script to make it more efficient.

Wondering why EnEsCe doesn't implement these very basic programming data structures such as your binary tree, linked lists [...] to the ScriptCore, but nice to have some guys like you around who provide these scripts.

Thank you!
« Last Edit: October 27, 2009, 09:15:54 am by CurryWurst »
Soldat Global Account System: #soldat.sgas @ quakenet