how i can Solution this ...?

hi ..
plezz how i can solution this algorethom

234*+
in Mathematics this solution
2 3*4+
2 12+
2+12
14
thx all
Build a postfix parser which has as side-effect the evaluation of the expression
thx bro but i need see the program ..
You'll have to write it, then.
closed account (z05DSL3A)
Using a stack
For each item in the postfix expression from the left:
    if the element is a number push it on the stack
    if the element is an operator (+,-,*, or /) then
        pop two numbers off the stack
        make a calculation: the second number popped-operator-first number
        push the result on the stack
When the loop is done the answer is the only item remaining on the stack.
Last edited on
thats good bro ...
but : redface:
i m new learning and i start with stack ..
i dont know how i can write this program ..
I feel like all I do lately is link to this site on these forums.

http://www.cplusplus.com/doc/tutorial/
Ok, look at this code, it's something I already had:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include "stdio.h"
#include "ctype.h"
int main(){
	int instr;
	int stack[100];
	int sp=0;
	while((instr=getchar())!=EOF){
		if(isdigit(instr)){
			if(sp>=100){
				fputs("stack overflow\n",stderr);
				continue;
			}else stack[sp++]=instr-'0';
		}else if(sp-1<0){
			fputs("stack underflow\n",stderr);
			continue;
		}
		else if(instr=='\n')printf("%d\n",stack[--sp]);
		else if(sp-2<0){
			fputs("stack underflow\n",stderr);
			continue;
		}
		if(instr=='+')stack[sp-2]+=stack[sp-1],sp--;
		if(instr=='-')stack[sp-2]-=stack[sp-1],sp--;
		if(instr=='*')stack[sp-2]*=stack[sp-1],sp--;
		if(instr=='/')stack[sp-2]/=stack[sp-1],sp--;
		if(instr=='%')stack[sp-2]%=stack[sp-1],sp--;
	}
}
thx all ...
thats vary good bro thx
Topic archived. No new replies allowed.