Evaluating expression tree using std::map<std::string, int>

This is a discussion on Evaluating expression tree using std::map<std::string, int> within the C++ Programming forums, part of the General Programming Boards category; I am not sure how to use the map function to evaluate my tree expression. the function goes like this ...

  1. #1
    Registered User
    Join Date
    Feb 2012
    Posts
    27

    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
    Last edited by Chucker; 04-30-2012 at 12:58 PM.

  2. #2
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,308
    std::map is not a function, it's a container.
    That evaluate function is simply asking for you to provide a map as its argument.
    So what have you tried, and what went wrong?
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help in evaluating postfix expression using stacks
    By gau in forum C++ Programming
    Replies: 11
    Last Post: 06-12-2007, 12:21 PM
  2. Evaluating logical AND expression
    By Micko in forum C Programming
    Replies: 11
    Last Post: 05-24-2006, 08:14 AM
  3. evaluating unary negation operator in an infix expression??
    By YevGenius in forum C++ Programming
    Replies: 7
    Last Post: 05-12-2004, 01:18 PM
  4. Evaluating an Expression
    By jpipitone in forum C Programming
    Replies: 15
    Last Post: 04-03-2003, 06:06 AM
  5. Replies: 4
    Last Post: 12-02-2002, 09:31 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21