lab_trees
Tempestuous Trees
|
Public Member Functions | |
AbstractSyntaxTree (typename BinaryTree< std::string >::Node *node) | |
Constructor that takes in a root node representing the pre-constructed AST. More... | |
double | eval () const |
Calculates the value from an AST (Abstract Syntax Tree). More... | |
Public Member Functions inherited from BinaryTree< std::string > | |
BinaryTree () | |
Constructor to create an empty tree. More... | |
BinaryTree (Node *heapNode) | |
Constructor to that wraps raw nodes as a BinaryTree class. More... | |
BinaryTree (const BinaryTree &other) | |
Copy constructor. More... | |
virtual | ~BinaryTree () |
Destructor; frees all nodes associated by this tree. More... | |
const BinaryTree & | operator= (const BinaryTree &rhs) |
Assignment operator. More... | |
void | clear () |
Frees all nodes associated with this tree and sets it to be empty. More... | |
void | insert (const std::string &elem) |
Inserts into the BinaryTree in BST order. More... | |
void | insertRandom (const std::string &elem, std::mt19937 &rng) |
Inserts the given value into the BinaryTree, taking a random path to the leaf where it is inserted. More... | |
void | print () const |
Prints the contents of the tree to stdout. More... | |
Node * | getRoot () const |
int | height () const |
This lab deals with the following six helper functions: More... | |
void | printLeftToRight () const |
Prints out the values of the nodes of a binary tree in order. More... | |
void | mirror () |
Flips the tree over a vertical axis, modifying the tree itself (not creating a flipped copy). More... | |
bool | isOrderedIterative () const |
isOrdered() function iterative version More... | |
bool | isOrderedRecursive () const |
isOrdered() function recursive version More... | |
void | getPaths (std::vector< std::vector< std::string >> &paths) const |
creates vectors of all the possible paths from the root of the tree to any leaf node and adds it to another vector. More... | |
int | sumDistances () const |
Each node in a tree has a distance from the root node - the depth of that node, or the number of edges along the path from that node to the root. More... | |
void | inOrder (std::vector< std::string > &treeVector) |
Uses vector to store values of the nodes of a binary tree in order. More... | |
Additional Inherited Members | |
Protected Attributes inherited from BinaryTree< std::string > | |
Node * | root |
AbstractSyntaxTree::AbstractSyntaxTree | ( | typename BinaryTree< std::string >::Node * | node | ) |
Constructor that takes in a root node representing the pre-constructed AST.
node | The root node of the preconstructed tree we want to wrap as an Abstract Syntax Tree |
double AbstractSyntaxTree::eval | ( | ) | const |
Calculates the value from an AST (Abstract Syntax Tree).
To parse numbers from strings, please use std::stod