javascript,postfix-notation,infix-notation

Your check y===("+" || "-" || "*" || "/" || "(" || ")")) is just y==="+" You either needs to break it up as if (y==="+" || y==="-" || ...) or you can use indexOf with an array or sting. if (["+","-","*","/","(",")"].indexOf(y) > -1) or a regular expression...

Your code gives the correct result for me: 6 2 / . The Value:: 3 Note that you are having inversed polish notation, i.e. the operand must follow after the values to operate on....

This would produce the output you want. The part next to the Logical OR | operator will matches the [-+*/$£] symbols from the remaining sub-string. Pattern pattern = Pattern.compile("\\d+(?:\\.\\d+)?(\\s\\d+(?:\\.\\d+)?)*\\s*[-+*/$£]|[-+*/$£]"); String input = "4.0 5.0 2.0 / + 7.0 - 11.0 34.0 2.0 / 3.0 / 1.0 * +"; Matcher matcher...

c,pointers,c-strings,postfix-notation,infix-notation

The problem is that you process p_newStr without initializint it, and only performing pointer arithmetic on it. I guess, that you wanted to see it as a string, adding chars to it. So first initialisze it: char* p_newStr = newStr; // It was unitinitalised, pointing at random location Then note...

c,linked-list,segmentation-fault,postfix-notation

Given this declaration ... char temp[256][256]; ... the loop termination condition here is wrong: for (int i = 0; temp[i]; ++i) { C multi-dimensional arrays are not Java-style arrays of array references. They are arrays of actual arrays. The expression temp[i] will not be false when i exceeds the number...

scala,postfix-notation,infix-notation

A way to do it is to use Dijkstra's Shunting Yard algorithm. Here is one implementation in Scala.

If you want to make it postfix, you have to put the name of the function after the arguments. That's all. def _getCurrentOperator(data): if data["type"] == "operation": _getCurrentOperator(data["rightArgument"]) _getCurrentOperator(data["leftArgument"]) valueList.append(data["operator"]) # here you do it right ... elif data["type"] == "function": if (data["name"] == "pi"): valueList.append(3.14159265359) else: for i in...

java,parsing,stack,postfix-notation

Try this one: String operand = ""; Change it also when if(Character.isDigit(postfixExpr.charAt(i+1)) == false){ s.push(operand); operand = ""; } ...

When you pop from the stack, op2 is the element at the top and op1 is at top-1. Change it to: op2 = nlist.pop(); op1 = nlist.pop(); To be more clear if your postfix expression is 56 - (so 5-6 in infix) your stack is | 6 | | 5...

RPN works the same for functions (including trigonometrics) as it does for operators. For trigonometrics, there is only a single argument (unlike operators, which generally have two). Your example sin(2*x^2+6)-(cos(x)/(1-x)) would become something like 2x2^*6+_sin_x_cos_1x-/- I put before-and-after underscores around sin and cos functions for clarity. Taken a little more...

The algorithm is : 1) read the string from the last element to the first and put each element in a stack of Strings (each element of your stack will be a single char operator or a word convertible to a number). 2) pop 3 elements convert the first two...

c++,c,pointers,recursion,postfix-notation

Your parsing is not quite doing recursion with two branches, but to answer your question, you need to malloc for the return value each time or the caller would not know when to free. I am keeping the example as C code because I didn't see any C++ in your...

c++,linked-list,stack,postfix-notation,infix-notation

Here's an issue: (expression[i]=='*'||'+'||'-'||'/' This does not do what you think it does. The fix: (expression[i] == '*' || expression[i] == '+' || expression[i] == '-' || expression[i] == '/') Edit 1: Searching strings Another method is: char c = expression[i]; const std::string operators="*+-/"; if (operators.find(c) != std::string::npos) { //...

java,stack,expression-trees,postfix-notation

A postfix expression is parsed from left to right - don't look at postfixExpr.length()-1 before you are there. Do not create and handle a root node in any special way. It will be top of the stack after the parse. Here's an error: node.operand = postfixExpr.charAt(i); This must be stored...

c++,linked-list,postfix-notation

My while loop should allow more than one line of input per the spec. You've already found getline. You can simply use that to read whole lines. That approach you've taken looks fine. I'm trying to skip over spaces in my loop, but instead my conditional appears to skip...