Hi guys :)

I'm just wondering how to start doing this problem?

Converting from Infix notation to Postfix one (Pastfix Calculator)

Of course in C++

using stack!

Any Idea how to implement the code?


thanks :)

>I'm just wondering how to start doing this problem?
Start by understanding the process of converting infix to postfix. Once you have that, it's not much of a stretch to see how a stack could be used to do it. Or you could do a google search and get one of the many existing implementations to use as a template.

Well, I'm confusing in the part of pushing the +, *, - and / in the stack

how can I push the operators +,-,* and /

according to the stronger like

if the infix given is A + B * C - G

in the stack it'll save + - then * !! how can I do that, actually this is the only part I'm getting stuck in :/

any ideas?

First input an infix expression. Push a left parenthesis onto stack and a right parenthesis at the end of the expression.

Then read the expression from left to right. If an operand or left parenthesis is encountered, push it onto stack. If an operator is encountered, repeatedly pop from stack every operator which has an equal or higher precedence, then push the operator encountered onto stack.

If a right parenthesis is encountered, repeatedly pop from stack until a left parenthesis is encountered.

Display each popped element.

Take a char type array and a variable to track the position of the top most element inserted.

Hope that helps.

so you meant I should have two Stacks? to do this?

yes

commented: Thanks for the help :) +1

You can do it with two stacks or with one. With two stacks you would have a stack of operators (single characters at a minimum, but full strings are more flexible). When you pop an operator off of the stack, use the operator itself to determine how many values to pop off of the other stack (binary operators take two, unary operators take one, etc...).

Or you can store strings in one stack while mixing the values and operators. The values go with an operator, so when you hit an unexpected type, you can perform the operation.

commented: Thanks for the help :) +1

Well, please can you explain exactly how to do it with one Stack?

actually the integers should input to a Queue and the operators in Stack

the part for Queue I did it, but I'm waiting for the operators how to input them to a Stack and re-arrange them!!?

Thanks :)

By the way, I have now two Stacks
Stack and Stack2

in Stack
I did an object for the Stack2 in one of the Stack member functions
like this
Stack2 go;

why it said undeclared identifier???

Is that correct what I did? if not then what's the correct?


thanks in advance :)

Thanks ArKM

but I need to know, how to call a function from a class in another class??

Like if I have a class called Stuck
and another Class called Stuck2

how do I call or make an object to use the functions in Stuck when I'm in Stuck2??

You may study programming languages like FORTH or Postscript how they do computing using stacks.

tesu

Well, we're not allowed to use the ready made libraries in C++ compiler

we have to write them as Classes :/


Well, I guess, I finished from it.. :)

thanks for all who tried to help :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.