BinaryTree

BinaryTree

Binary Tree에 저장되어 있는 요소들은 트리 형태로 표현되며 요소 간에 부모, 자식 관계가 존재하고 트리의 형태는 complete binary tree이다.

Constructor

new BinaryTree()

Author:
  • seeung0305@naver.com
Example
var bt = new BinaryTree ();

Methods

(static) clear()

This method is used to nullify this binary tree and make all variables initial.
Example
var bt = new BinaryTree ();
bt.push(1);
bt.push(2);
bt.push(3);
bt.clear();

(static) inOrder(value)

This method is used for tree traversal. Traversal order is left -> parent -> right.
Example
var bt = new BinaryTree ();
bt.push(1);
bt.push(2);
bt.push(3);
bt.inOrder(this.root); // Tree :  2-1-3
Parameters:
Name Type Description
value undefined The node is used to tree traversal recursively.
Throws:
This method returns 'false' if parameter is missing or null if the node has no data.

(static) isEmpty() → {Boolean}

This method is used to check if this binary tree is empty.
Example
var bt = new BinaryTree ();
var ret1 = bt.isEmpty(); // ret1 = true
bt.pushMin(1);
var ret2 = bt.isEmpty(); // ret2 = false
Returns:
This method returns ‘true’ if this binary tree is empty or ‘false’ if this binary tree is not empty.
Type
Boolean

(static) pop()

This method is used to remove the very first value from this binary tree.
Example
var bt = new BinaryTree ();
bt.push(1);
bt.push(2);
bt.push(3);
bt.pop(); // 1 will be removed
Throws:
This method returns 'false' if binary tree is empty.

(static) postOrder(value)

This method is used for tree traversal. Traversal order is left -> right -> parent.
Example
var bt = new BinaryTree ();
bt.push(1);
bt.push(2);
bt.push(3);
bt.postOrder(this.root); // Tree :  2-3-1
Parameters:
Name Type Description
value undefined The node is used to tree traversal recursively.
Throws:
This method returns 'false' if parameter is missing or null if the node has no data.

(static) preOrder(value)

This method is used for tree traversal. Traversal order is parent -> left -> right.
Example
var bt = new BinaryTree ();
bt.push(1);
bt.push(2);
bt.push(3);
bt.preOrder(this.root);  // Tree :  1-2-3
Parameters:
Name Type Description
value undefined The node is used to tree traversal recursively.
Throws:
This method returns 'false' if parameter is missing or null if the node has no data.

(static) push(value)

This method is used to insert the specified value into this binary tree.
Example
var bt = new BinaryTree ();
bt.push(1);
bt.push(2);
bt.push(3);
Parameters:
Name Type Description
value undefined The value to be inserted to this binary tree.
Throws:
This method returns null if parameter is missing.

(static) size() → {Number}

This method is used to get the number of values in this binary tree.
Example
var bt = new BinaryTree ();
bt.push(1);
bt.push(2);
bt.push(3);
var size = bt.size(); // size = 3
Returns:
This method returns the number of values in this binary tree.
Type
Number

(static) state()

This method shows state of the binary_tree.
Example
var bt = new BinaryTree ();
bt.push(1);
bt.push(2);
bt.push(3);
bt.state();  // InOder : 2-1-3, PreOrder : 1-2-3, PostOrder : 2-3-1