1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Infix to Postfix Conversion

  1. Apr 24, 2009 #1
    1. The problem statement, all variables and given/known data

    I need to write a method for the PostfixConversion class:

    public static boolean precedence(char first, char second)

    The precedence method determines the precedence between two operators. (here, they are either '+', '-', '*', or '/') If the first operator is of higher or equal precedence than the second operator, it returns the value true; otherwise, it returns the value false. (for instance, if the new operator is '+' or '-', then all operators (+,-,*,/) have precedence greater than or equals to the operator. If the new operator is '*' or '/', then only the operators '*' and '/' have precedence greater than or equals to the operator.)



    2. Relevant equations



    3. The attempt at a solution

    public static boolean precedence(char first, char second)
    {
    int char1Index=0;
    int char2Index=0;
    String precedence = "-+*/";
    for(int i=0; i<precedence.length(); i++)
    {
    if(first==precedence.charAt(i)) char1Index=i;
    if(second==precedence.charAt(i)) char2Index=i;
    }
    if(((char1Index==0)||(char1Index==1)) && (char2Index>1)) return false;
    else return true;
    }

    I feel like something is messed up. Let me know if I am making any mistakes. I didn't really understand what I was supposed to be doing. This was my best guess.
    1. The problem statement, all variables and given/known data



    2. Relevant equations



    3. The attempt at a solution
     
  2. jcsd
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Can you offer guidance or do you also need help?
Draft saved Draft deleted



Similar Discussions: Infix to Postfix Conversion
  1. C++: Postfix to Infix (Replies: 1)

Loading...