Answered # Any Idea of doing (Infix to Postfix calculater) using Stack?

Narue 5,707 Discussion Starter Q8iEnG jmines 1 jmines 1 Featured Reply Narue 5,707 Discussion Starter Q8iEnG Discussion Starter Q8iEnG Featured Reply ArkM 1,090 Discussion Starter Q8iEnG tesuji 135 Discussion Starter Q8iEnG Need some help with this Array. I am trying to get the sum of the even numbers and the sum of the odd numbers using a for each loop. I know the answers to what I am trying to achive are sum of even = 84 and the sum of ...

0

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

0

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?

0

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.

0

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

Hope that helps.

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.

0

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

0

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

1

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

0

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

0

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

tesu

0

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

This question has already been answered. Start a new discussion instead.

Recommended Articles

When I execute this progammatically, I get a table with row heights much larger than when I do this manually.

Note : Sel is the Word.Selection object and the Clipboard contains an Excel Table.

```
public void AddClipboard()
{
Sel.PasteExcelTable(false,false, false);
var t = Sel.Tables[Sel.Tables.Count];
t.AutoFitBehavior(Word.WdAutoFitBehavior.wdAutoFitContent);
}
```

the function that I created to find the ...