0

can any one give a slight hint about the alogirthm to evaluate a prefix expression using queue.i tried a lot bt now atthe dead end,

3
Contributors
4
Replies
10
Views
6 Years
Discussion Span
Last Post by Schol-R-LEA
0

*+abc should be treated as (a+b)*c so in a prefix expression traverse the expression until you find two operands after an operator and use that operator on that operand then go on doing the same thing for the rest of expression. If you know queue then you can obviously play around. You can even use STL for the ease of programming.

0

i started it with the same idea.bt after using the operator on two operand where should i keep the evaluated result.as i am using a character array to implement queue so i cant put that value to that array if it is a multidigit number which is case most of the time.then it will give garbage value.pls give an soln to this problem..

0

If you can make a queue of chars so can you make a queue of strings and in a string you can store the characters which form the entire number. There can be many ways to solve a problem (efficient and in efficient). you just need to choose how you would want to solve it.

0

You could also implement a discriminant union and make a queue of those; this would let you use doubles for the numbers.

enum QueueElementType {NUMBER, OPERATOR};

struct QueueElement 
{
    enum QueueElementType type;
    union 
    {
        double number;
        char operator;
    } element;

    struct QueueElement *next;
};

Edited by Schol-R-LEA: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.