Tree

Implementation of tree.

TreeNode:__init(key, val)

View source

Constructor.

TreeNode:children()

View source

Returns:

  • (table) children of this node

TreeNode:__tostring__()

View source

Returns:

  • (string) string representation

TreeNode:subtreeToString(prefix, isLeaf)

View source

Arguments:

  • prefix (string): string to add before each line.
  • isLeaf (boolean): whether the subtree is a leaf.

Returns:

  • (string) string representation

Tree:__tostring__()

View source

Returns:

  • (string) string representation

Tree:size()

View source

Returns:

  • (int) number of nodes in the tree