BinaryTreeNode

A binary tree node from which you can build a binary tree.

A Binary Tree is a simplified tree structure in which every node is only allowed to have up to two children nodes, which are called the left and right child.

Summary
BinaryTreeNodeA binary tree node from which you can build a binary tree.
Functions
preorderPerforms a preorder traversal on a tree.
inorderPerforms an inorder traversal on a tree.
postorderPerforms a postorder traversal on a tree.
Variables
leftThe left child node being referenced.
rightThe right child node being referenced.
parentThe parent node being referenced.
dataThe node’s data.
Functions
BinaryTreeNodeCreates an empty node.
setLeftWrites data into the left child.
setRightWrites data into the right child.
isLeftChecks if the node is a left node relative to its parent node.
isRightChecks if the node is a right node relative to its parent node.
getDepthComputes the depth of a tree.
countRecursively counts the total number of nodes including this node.
destroyRecursively clears the tree by deleting all child nodes underneath the node the method is called on.
toStringPrints out a string representing the current object.

Functions

preorder

public static function preorder(node: BinaryTreeNode,
process: Function):void

Performs a preorder traversal on a tree.  This processes the current tree node before its children.

Parameters

nodeThe node to start from.
processA process function applied to each traversed node. 

inorder

public static function inorder(node: BinaryTreeNode,
process: Function):void

Performs an inorder traversal on a tree.  This processes the current node in between the child nodes.

Parameters

nodeThe node to start from.
processA process function applied to each traversed node. 

postorder

public static function postorder(node: BinaryTreeNode,
process: Function):void

Performs a postorder traversal on a tree.  This processes the current node after its children.

Parameters

nodeThe node to start from.
processA process function applied to each traversed node. 

Variables

left

public var left: BinaryTreeNode

The left child node being referenced.

right

public var right: BinaryTreeNode

The right child node being referenced.

parent

public var parent: BinaryTreeNode

The parent node being referenced.

data

public var data: *

The node’s data.

Functions

BinaryTreeNode

public function BinaryTreeNode(obj: *)

Creates an empty node.

Parameters

objThe node’s data. 

setLeft

public function setLeft(obj: *):void

Writes data into the left child.

Parameters

objThe data. 

setRight

public function setRight(obj: *):void

Writes data into the right child.

Parameters

objThe data. 

isLeft

public function isLeft():Boolean

Checks if the node is a left node relative to its parent node.

Returns

True if this node is left, otherwise false. 

isRight

public function isRight():Boolean

Checks if the node is a right node relative to its parent node.

Returns

True if this node is right, otherwise false. 

getDepth

public function getDepth(node: BinaryTreeNode = null):int

Computes the depth of a tree.

Returns

The depth of the tree. 

count

public function count():int

Recursively counts the total number of nodes including this node.

destroy

public function destroy():void

Recursively clears the tree by deleting all child nodes underneath the node the method is called on.

toString

public function toString():String

Prints out a string representing the current object.

Returns

A string representing the current object. 

public static function preorder(node: BinaryTreeNode,
process: Function):void
Performs a preorder traversal on a tree.
public static function inorder(node: BinaryTreeNode,
process: Function):void
Performs an inorder traversal on a tree.
public static function postorder(node: BinaryTreeNode,
process: Function):void
Performs a postorder traversal on a tree.
public var left: BinaryTreeNode
The left child node being referenced.
public var right: BinaryTreeNode
The right child node being referenced.
public var parent: BinaryTreeNode
The parent node being referenced.
public var data: *
The node’s data.
public function BinaryTreeNode(obj: *)
Creates an empty node.
public function setLeft(obj: *):void
Writes data into the left child.
public function setRight(obj: *):void
Writes data into the right child.
public function isLeft():Boolean
Checks if the node is a left node relative to its parent node.
public function isRight():Boolean
Checks if the node is a right node relative to its parent node.
public function getDepth(node: BinaryTreeNode = null):int
Computes the depth of a tree.
public function count():int
Recursively counts the total number of nodes including this node.
public function destroy():void
Recursively clears the tree by deleting all child nodes underneath the node the method is called on.
public function toString():String
Prints out a string representing the current object.
Close