Evaluating expression tree using std::map<std::string, int>
I am not sure how to use the map function to evaluate my tree expression. the function goes like this
Code:
int Tree::evaluate(std::map< std::string, int > ipMap){
and my teacher gave me a hint to look at my function to postorder print for an example but i am not sure how it applies to this. Here it is:
Code:
void Tree::postOrderPrint(){
Code:
void Tree::postOrderPrint(){
if(NodeType==TYPE_OPERATOR)
{
leftPtr->postOrderPrint();
rightPtr->postOrderPrint();
std::cout<< Op << " " ;
}
else
{
std::cout<< Op << " " ;
}
}
what ive tried was wrong. but im just supposed to use map to find if the element in the tree expression is a + - * or / i believe, and if so use that operator to evaluate the left aand right subtrees. Keep in mind that the string is parsed and the tree is already buit