hi ppl...am gettin a prob in the o/p of the postfix evaluation...i checked out the prog in the other forum,but this prog is of my own so pls help me....nd yeah please tell me how to post the code....
Code: #include<iostream.h> #include<ctype.h> #define SS 100 #define TRUE 1 #define FALSE 0 struct stack { int items[SS],top; }; struct stack s; int empty(struct stack *ps) { if(ps->top==SS-1) return TRUE; else return FALSE; } int popandtest(struct stack *ps,int *px,int *pund) { if(empty(ps)) { *pund=TRUE; return 1; } *pund=FALSE; *px=ps->items[ps->top]; return(*px); } void pushandtest(struct stack *ps,int x,int *pover) { if(!empty(ps)) { *pover=TRUE; return; } *pover=FALSE; ps->items[++(ps->top)]=x; return; } int evalue(struct stack *ps,char post[SS]) { int i=0,op1,op2,r,v,underflow,overflow; for(;post[i]!='\0';i++) { if(!isalpha(post[i])) { op2=popandtest(&s,&s.items[s.top],&underflow); op1=popandtest(&s,&s.items[s.top],&underflow); switch(post[i]) { case '+':r=op1+op2; pushandtest(&s,r,&overflow); break; case '-':r=op1-op2; pushandtest(&s,r,&overflow); break; } } } v=popandtest(&s,&s.items[s.top],&underflow); return(v); } main() { char p[SS]; int i,r; cout<<"Enter a valid postfix expression"; cin>>p; for(i=0;p[i]!='\0';i++) { if(isalpha(p[i])) { cout<<"enter value for"<<p[i]<<endl; cin>>s.items[i]; s.top++; } } r=evalue(&s,p); cout<<"value="<<r; return 0; }
one error i could myself rectify later was tat i wasnt implementing stacks completly...i.e my top pointer was pointing somewhere else...when i rectified it the code works properly for 2 variables but not for 3 and higher....the above code *isnt* the modified one....
I don't think you understand what I mean. You say you have problems with the code. You also say that you have changed the code. Suppose that we invest our time, on the old code, and point out some problems. Perhaps your newer code has already addressed those problems, and solved them. That would be a waste of our time. I realize that the time that we devote is free. Two hours invested at zero dollars per hour costs the same as two hundred hours at zero dollars per hour. Nevertheless, I would prefer to invest my time in a productive manner. Go figure.
AAAAhhhhhhhhhh....u r too much confusing...neways forget it...thanks for all the help u could give(i aint taunting)....in the mean time i was able to come up a cod of mine without the structures...will try to make this work on my own....am really sorry for wastin u ppl's time....thanks neways!!!!cya!!