DAWEN LEE

Greenhorn
+ Follow
since Nov 13, 2004
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by DAWEN LEE

how to uses java to write a program like this:
The input string, such as "7 * ( 23 - 105 / 15 ) - 19", is converted by the tokenizer into a sequence of tokens that are enqueued into the first buffer (i.e. queue) q1.

The validate method then dequeues the tokens, one at a time, and checks that the expression be valid. Each token is copied (i.e. enqueued) into the second buffer q2. If the expression is not valid an InvalidExpressionException is thrown and the whole process is terminated.

More detail on this method is given below.

The infix2postfix method converts the sequence of tokens (from q2) by re-ordering into postfix sequence and enqueues them into q3. Postfix notation is known commonly as reverse Polish notation.

The expression

7 * ( 23 - 105 / 15 ) - 19
with infix operators would appear as
7 23 105 15 / - * 19 -
in reverse Polish. The operator appears after the two values to which it applies. Brackets are not needed.

A means of converting infix expressions into reverse Polish is given below.

The evaluate method uses a stack to support evaluation of the reverse Polish expression and returns the result.
if someone knows how to do it, please help me! Thank you very much!!
19 years ago