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 :)

Q8iEnG
0
Junior Poster

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 :)

Jump to Post>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 …

Jump to Postyes

Jump to PostYou 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 …

Jump to PostUse a classic approach (come back to 60th;). See, for example:

http://everything2.com/index.pl?node_id=1293134

http://scriptasylum.com/tutorials/infix_postfix/algorithms/infix-postfix/index.htm

http://cis.stvincent.edu/html/tutorials/swd/stacks/stacks.html…

Narue
5,707
Bad Cop
Team Colleague

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.

Q8iEnG
0
Junior Poster

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?

jmines
1
Newbie Poster

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.

jmines
1
Newbie Poster

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

Hope that helps.

Q8iEnG
0
Junior Poster

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

jmines
1
Newbie Poster

yes

Q8iEnG
commented:
Thanks for the help :)
+1

Narue
5,707
Bad Cop
Team Colleague

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.

Q8iEnG
commented:
Thanks for the help :)
+1

Q8iEnG
0
Junior Poster

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 :)

Q8iEnG
0
Junior Poster

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 :)

ArkM
1,090
Postaholic

Use a classic approach (come back to 60th;). See, for example:

http://everything2.com/index.pl?node_id=1293134

http://scriptasylum.com/tutorials/infix_postfix/algorithms/infix-postfix/index.htm

http://cis.stvincent.edu/html/tutorials/swd/stacks/stacks.html

Of course, these three links are not ideal, but...

Q8iEnG
commented:
Thanks for the small help :)
+1

Q8iEnG
0
Junior Poster

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??

tesuji
135
Master Poster

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

tesu

Q8iEnG
0
Junior Poster

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, learning, and sharing knowledge.