Updated specific locations to be searchable, take a look at Las Vegas as an example.

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

1
Using Shunting Yard Algorithm for Calculator
Post Flair (click to view more posts with a particular flair)
Post Body

Hey everybody first-time post. The issue I am running into is currently I am creating a token for each character which is fine, but when I have an expression like (10 2) it should equal 12, not 2. I have tried adding in a delimiter as shown commented out, but I do not quite understand exactly how a StringTokenizer works. From my understanding, I see two different ways of solving this issue. First, use the StringTokenizer to split the expression for operators( -*/) and values. Second, ive considered changing the else statement. I'm posting here because I have been trying to wrap my mind around this and I could use a push in the right direction.

// shuntingYard algorithm to convert fromc infix to postfix
public String shuntingYard(String infix) {
StringBuilder output = new StringBuilder();
Stack<String> stack = new Stack<String>();

//String DELIMITERS = "\" -*/^\"";

//this.tokenizer = new StringTokenizer(RPN, DELIMITERS, true);
for (String token : infix.split("")) {
//operator
if (Operator.operators.containsKey(token)) {
while ( ! stack.isEmpty() && isHigherPrec(token, stack.peek())) {
output.append(stack.pop()).append(' ');
}
stack.push(token);
}
//left parenthesis
else if (token.equals("(")) {
stack.push(token);
}
//right parenthesis
else if (token.equals(")")) {
while ( ! stack.peek().equals("(")) {
output.append(stack.pop()).append(' ');
}
stack.pop();
}
//digit
else {
// Find a way to check for multidigits
output.append(token).append(' ');
}
}
while ( ! stack.isEmpty()) {
output.append(stack.pop()).append(' ');
}
return output.toString();
}

Author
Account Strength
80%
Account Age
7 years
Verified Email
Yes
Verified Flair
No
Total Karma
89
Link Karma
63
Comment Karma
26
Profile updated: 2 days ago
Posts updated: 1 year ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
5 years ago