class Graphlb::DataStructures::BinaryTreeNode

Overview

Provides a Binary tree implementation. This node allows only two child nodes (left and right child). It also provides direct access to the left or right child, including assignment to the same.

This inherits from the {TreeNode} class.

Defined in:

graphlb/data_structures/binary_tree.cr

Instance Method Summary

Instance methods inherited from class Graphlb::DataStructures::TreeNode

<<(child) <<, [](name_or_index, num_as_name = false) [], add(child, at_index = -1) add, children : Array(Graphlb::DataStructures::TreeNode)
children(&block)
children
, content : Int32? content, content=(content : Int32?) content=, each(&block)
each
each
, each_leaf
each_leaf(&block)
each_leaf
, first_sibling first_sibling, has_children? has_children?, has_content? has_content?, in_degree in_degree, insertion_range insertion_range, is_first_sibling? is_first_sibling?, is_last_sibling? is_last_sibling?, is_leaf? is_leaf?, is_only_child? is_only_child?, is_root? is_root?, lam(node, prefix) lam, last_sibling last_sibling, name : String name, next_sibling next_sibling, node_depth node_depth, node_height node_height, out_degree out_degree, parent : TreeNode? parent, parent=(parent) parent=, parentage parentage, previous_sibling previous_sibling, print_tree(level = self.node_depth, max_depth = nil) print_tree, remove!(child) remove!, remove_from_parent! remove_from_parent!, rename(new_name) rename, replace!(old_child, new_child) replace!, replace_with(node) replace_with, root root, set_as_root! set_as_root!, siblings siblings

Constructor methods inherited from class Graphlb::DataStructures::TreeNode

new(name, content = nil) new

Instance Method Detail

def is_left_child? #

true if the receiver node is the left child of its parent. Always returns false if it is a root node.

@return [Boolean] true if this is the left child of its parent.


[View source]
def is_right_child? #

true if the receiver node is the right child of its parent. Always returns false if it is a root node.

@return [Boolean] true if this is the right child of its parent.


[View source]
def left_child #

Left child of the receiver node. Note that left Child == first Child.

@return [BinaryTreeNode] The left most (or first) child.


[View source]
def left_child=(child) #

Sets the left child of the receiver node. If a previous child existed, it is replaced.

@param [BinaryTreeNode] child The child to add as the left-side node.

@return [BinaryTreeNode] The assigned child node.


[View source]
def right_child #

Right child of the receiver node. Note that right child == last child unless there is only one child.

Returns nil if the right child does not exist.

@return [BinaryTreeNode] The right child, or nil if the right side child does not exist.


[View source]
def right_child=(child) #

Sets the right child of the receiver node. If a previous child existed, it is replaced.

@param [BinaryTreeNode] child The child to add as the right-side node.

@return [BinaryTreeNode] The assigned child node.


[View source]
def swap_children #

Swaps the left and right child nodes of the receiver node with each other.


[View source]