September 23rd, 2012, 03:39 PM

Evaluating Prefix Expressions using stack
So, I have to use a Double stack to evaluate a Prefix Expression. However, I am totally stuck. I have to evaluate numbers that are above 10. So I can't just read the line and reverse the string and then look at each char at a time.
The Input is something like + * 1 4 34
Can anyone point me in the right direction
September 23rd, 2012, 04:00 PM

Originally Posted by akaicewolf
The Input is something like + * 1 4 34
I can't write URL. But now, I saw this task!
Write in google : java Binary expression tree
First link is for you: *******.ewu.edu
There are source files.
If you can, write right solution(or clone link) in this place for progeny.
September 23rd, 2012, 04:02 PM

Originally Posted by franktan
I can't write URL. But now, I saw this task!
Write in google : java Binary expression tree
First link is for you: *******.ewu.edu
There are source files.
If you can, write right solution(or clone link) in this place for progeny.
Thanks, but I have to do it using Stacks not trees
September 23rd, 2012, 04:09 PM

Ooh, sorry. I Find Stack in wikipedia: Binary expression tree
I can't help you more. =(
September 23rd, 2012, 04:22 PM

Do you have the algorithm for processing the tokens as they are read one by one from the input?
Given the algorithm it should be possible to design and write code to do it.
September 23rd, 2012, 04:32 PM

Originally Posted by NormR
Do you have the algorithm for processing the tokens as they are read one by one from the input?
Given the algorithm it should be possible to design and write code to do it.
I am a little bit confused by what you mean. So far I have a Double Stack class but I have no idea how to use it to evaluate the expression.
September 23rd, 2012, 04:36 PM

An algorithm is a list of steps a process/program should take to solve a problem.
What are the steps your program should take? These steps are not lines of code.
One of the tools the program will use will be a stack.
What is a "Double Stack"?
September 23rd, 2012, 04:39 PM

Originally Posted by NormR
An algorithm is a list of steps a process/program should take to solve a problem.
What are the steps your program should take? These steps are not lines of code.
One of the tools the program will use will be a stack.
What is a "Double Stack"?
By Double stack, it is a single stack but is is able to store two different sets of things. So the first part of the stack is designed to store operands and the second part is designed to store operators.
I don't have an algorithm that is what I am trying to figure out. My directions are "Using a Double Stack implement a program that evaluates Prefix expressions". So I am trying to figure out how to go about this.
September 23rd, 2012, 04:44 PM

I don't have an algorithm
You need to find that before continuing. Do you have an algorithm for solving the problem using any tools?
Not sure what you mean by parts of a stack: one part for numbers, one part for operators.
How is that different from two separate stacks: one for numbers, one for operators?
What is the advantage of a Double Stack?
September 23rd, 2012, 04:49 PM

Originally Posted by NormR
You need to find that before continuing. Do you have an algorithm for solving the problem using any tools?
Not sure what you mean by parts of a stack: one part for numbers, one part for operators.
How is that different from two separate stacks: one for numbers, one for operators?
What is the advantage of a Double Stack?
Well that is what I am asking, to help me find an algorithm to solve the problem. If I had the algorithm and the tools I wouldn't need help unless debugging.
It is not any different then having two separate stacks. I do not know the advantage as the assignment specified using a Double Stack
September 23rd, 2012, 04:50 PM

Have you tried googling for the algorithm?
September 23rd, 2012, 04:56 PM

Originally Posted by NormR
Have you tried googling for the algorithm?
Yes. However most of the solutions assume that the input is 1 2 3 + , instead of  + 1 2 3. Or the other solutions assume that the numbers don't go any higher then 10.
For instance to solve +1 23 4. You would start at the end and look at one character at a time until you hit an operator. However, if you look at one character at a time then if the input is + 1 23 4, the number 23 will be treated it as two separate numbers
September 23rd, 2012, 05:11 PM

solutions assume that the numbers don't go any higher then 10.
An algorithm would not consider the size of the numbers. You must have been looking at someone's code.
start at the end and look at one character at a time
Why not look at one token at a time?
if you look at one character at a time
You are trying to write code before you have a design/algorithm. Get the design/algorithm first, then write the code.
September 23rd, 2012, 05:16 PM

Originally Posted by NormR
An algorithm would not consider the size of the numbers. You must have been looking at someone's code.
Why not look at one token at a time?
You are trying to write code before you have a design/algorithm. Get the design/algorithm first, then write the code.
How would I look at one token at a time?
September 23rd, 2012, 05:19 PM

Do you have the algorithm yet?
You're working on how to code before getting a design.
There are ways to get tokens from a String. Depends on which end of the String are you starting from?