| Package | de.polygonal.ds |
| Class | public class BinarySearchTree |
| Inheritance | BinarySearchTree Object |
| Implements | Collection |
| Property | Defined By | ||
|---|---|---|---|
| root : BinaryTreeNode
The root node being referenced. | BinarySearchTree | ||
| size : int [read-only]
The total number of items. | BinarySearchTree | ||
| Method | Defined By | ||
|---|---|---|---|
BinarySearchTree(compare:Function = null)
Initializes a BST tree with a given comparison function. | BinarySearchTree | ||
clear():void
The tree is cleared recursively, starting from the node on which the
method is called. | BinarySearchTree | ||
contains(obj:*):Boolean
Determines if the collection contains a given item. | BinarySearchTree | ||
dump():String
Prints out all elements (for debug/demo purposes). | BinarySearchTree | ||
find(obj:*):BinaryTreeNode
Finds a piece of data in the tree and returns a reference to the node
that contains a match, or null if no match is found. | BinarySearchTree | ||
An iterator is not supported, use BinaryTreeNode.preorder(),
inorder() and postorder() instead. | BinarySearchTree | ||
insert(obj:*):void
Inserts an item into the tree. | BinarySearchTree | ||
isEmpty():Boolean
Checks if the collection is empty. | BinarySearchTree | ||
remove(node:BinaryTreeNode):void
Removes a node from the BST. | BinarySearchTree | ||
toArray():Array
Converts the collection into an array. | BinarySearchTree | ||
toString():String
Prints out a string representing the current object. | BinarySearchTree | ||
| root | property |
public var root:BinaryTreeNodeThe root node being referenced.
| size | property |
size:int [read-only] The total number of items.
public function get size():int| BinarySearchTree | () | Constructor |
public function BinarySearchTree(compare:Function = null)Initializes a BST tree with a given comparison function. The function should return -1 if the left is 'less than' the right, 0 if they are equal, and 1 if the left is 'greater than' the right. If the function is omitted, the BST uses a default function for comparing integers.
Parameterscompare:Function (default = null) — The comparison function.
|
| clear | () | method |
public function clear():voidThe tree is cleared recursively, starting from the node on which the method is called.
Clears all items.| contains | () | method |
public function contains(obj:*):BooleanDetermines if the collection contains a given item.
Parameters
obj:* — The item to search for.
|
Boolean — True if the item exists, otherwise false.
|
| dump | () | method |
public function dump():StringPrints out all elements (for debug/demo purposes).
ReturnsString — A human-readable representation of the structure.
|
| find | () | method |
public function find(obj:*):BinaryTreeNodeFinds a piece of data in the tree and returns a reference to the node that contains a match, or null if no match is found.
Parameters
obj:* — The data to find.
|
BinaryTreeNode — A node containing the data or null if the data wasn't found.
|
| getIterator | () | method |
public function getIterator():IteratorAn iterator is not supported, use BinaryTreeNode.preorder(), inorder() and postorder() instead.
ReturnsIterator |
See also
| insert | () | method |
public function insert(obj:*):voidInserts an item into the tree.
Parameters
obj:* — The data.
|
| isEmpty | () | method |
public function isEmpty():BooleanChecks if the collection is empty.
ReturnsBoolean — True if empty, otherwise false.
|
| remove | () | method |
public function remove(node:BinaryTreeNode):voidRemoves a node from the BST.
Parameters
node:BinaryTreeNode — The node to remove.
|
| toArray | () | method |
public function toArray():ArrayConverts the collection into an array.
ReturnsArray — An array.
|
| toString | () | method |
public function toString():StringPrints out a string representing the current object.
ReturnsString — A string representing the current object.
|