Click here to Skip to main content
15,904,155 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralHIde logical disk Pin
faroqtam1-Nov-04 6:20
faroqtam1-Nov-04 6:20 
GeneralRe: HIde logical disk Pin
David Crow1-Nov-04 6:33
David Crow1-Nov-04 6:33 
GeneralRe: HIde logical disk Pin
John M. Drescher1-Nov-04 7:27
John M. Drescher1-Nov-04 7:27 
GeneralRe: HIde logical disk Pin
David Crow1-Nov-04 8:14
David Crow1-Nov-04 8:14 
GeneralRe: HIde logical disk Pin
Ryan Binns1-Nov-04 17:59
Ryan Binns1-Nov-04 17:59 
GeneralRe: HIde logical disk Pin
ThatsAlok3-Nov-04 18:31
ThatsAlok3-Nov-04 18:31 
GeneralChanging a dialog from Popup to Child at runtime Pin
Ali Niaz1-Nov-04 6:14
Ali Niaz1-Nov-04 6:14 
GeneralRe: Changing a dialog from Popup to Child at runtime Pin
faroqtam1-Nov-04 6:26
faroqtam1-Nov-04 6:26 
GeneralOpening an MFC Application in Splitter Pane Pin
Ali Niaz1-Nov-04 6:04
Ali Niaz1-Nov-04 6:04 
GeneralRe: Opening an MFC Application in Splitter Pane Pin
David Crow1-Nov-04 6:34
David Crow1-Nov-04 6:34 
GeneralCalculator Using Stacks Pin
civicnar1-Nov-04 5:54
civicnar1-Nov-04 5:54 
GeneralRe: Calculator Using Stacks Pin
David Crow1-Nov-04 6:38
David Crow1-Nov-04 6:38 
GeneralRe: Calculator Using Stacks Pin
civicnar1-Nov-04 6:53
civicnar1-Nov-04 6:53 
GeneralRe: Calculator Using Stacks Pin
John M. Drescher1-Nov-04 7:37
John M. Drescher1-Nov-04 7:37 
GeneralRe: Calculator Using Stacks Pin
John M. Drescher1-Nov-04 7:41
John M. Drescher1-Nov-04 7:41 
GeneralRe: Calculator Using Stacks Pin
civicnar1-Nov-04 7:57
civicnar1-Nov-04 7:57 
GeneralRe: Calculator Using Stacks Pin
David Crow1-Nov-04 8:31
David Crow1-Nov-04 8:31 
GeneralRe: Calculator Using Stacks Pin
Joaquín M López Muñoz1-Nov-04 8:38
Joaquín M López Muñoz1-Nov-04 8:38 
GeneralRe: Calculator Using Stacks Pin
civicnar1-Nov-04 8:49
civicnar1-Nov-04 8:49 
GeneralRe: Calculator Using Stacks Pin
civicnar1-Nov-04 8:52
civicnar1-Nov-04 8:52 
GeneralRe: Calculator Using Stacks Pin
Joaquín M López Muñoz1-Nov-04 8:57
Joaquín M López Muñoz1-Nov-04 8:57 
GeneralRe: Calculator Using Stacks Pin
civicnar1-Nov-04 9:03
civicnar1-Nov-04 9:03 
GeneralRe: Calculator Using Stacks Pin
Joaquín M López Muñoz1-Nov-04 9:26
Joaquín M López Muñoz1-Nov-04 9:26 
Well, I cannot solve your homework, so I hope some advice can put you on the right track.

First of all, this kind of problem is usually solved with one stack, not two. By inserting the numbers into one stack and the operands into another, you're losing crucial information about the orifinal postfix expression. For instance, consider the two expressions:
1 2 + 3 * [3 * (1 + 2) = 9]
1 2 3 + * [(3 + 2) * 1 = 5]
According to your schema, these two expressions would be stored just the same:
number stack: 3 2 1
operation stack: * +
so you're clearly doing it the wrong way. Ok so far? What you have to do is store everything into one single stack. As the stack can have to types of elements (numbers and operations), create a <ode>struct capable of storing both things, like for instance:
struct stack_element
{
  bool is_operation;
  // the rest you can figure it out: some set of fields
  // or another will be used depending on is_operation
}
Now you have your stack with the given postfix expression conveniently stored in reverse order. You have to devise an algorithm to evaluate the contents of the stack. You can rely on the following two reduction policies:
  • If the top element of the stack is a number, this is what the stack evaluates to.
  • If the top element is an operation then:
    1. Extract it from the stack.
    2. Recursively evaluate the first operand, yielding a number and leaving the expression for the second operand in the stack.
    3. Evaluate the second operand the same way.
    4. You have your operation and your two operands, calculate this and you're done.
I hope this is of some help. If you make some progress in your program and get stucked again, repost here trying to be specific about the particular problem you've run into.

Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
Want a Boost forum in Code Project? Vote here[^]!
GeneralRe: Calculator Using Stacks Pin
civicnar1-Nov-04 9:32
civicnar1-Nov-04 9:32 
QuestionHow to Start MFC App with arguments Pin
nonothing1-Nov-04 5:38
nonothing1-Nov-04 5:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.