cpp
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
#include<process.h>
#include<iomanip.h>
struct node
{
int data;
node *next;
};
node *top;
//node *s;
void initialize()
{
top=NULL;
}
void push(int x)
{
node *p=new node;
if(p!=NULL)
{
if(top==NULL)
{
p->data=x;
p->next=NULL;
top=p;
}
else
{
p->next=top;
top=p;
}
}
else
{
cout<<"\t\tError! The system run out of memory"<<endl;
exit(1);
}
cout<<top->data;
}
int pop()
{
node *p=top;
if(top!=NULL)
{
top=p->next;
return p->data;
}
cout<<"\t\tError! The stack is empty"<<endl;
return 0;
}
void main()
{
clrscr();
int value,x; int y,z;
initialize();
const int size=50;
int e[size];
cout<<"\n\n\t\t\tEnter Postfix expression\n"<<endl;
cout<<"\n\n\t\t\t============================="<<endl;
cin.getline(e,100)
for(int i=0;i<strlen(e);i++)
{
if(e!='\0')
if((e[i]>='0')&&(e[i]<='9'))
{
int x;
x=<int>(e[i]);//casting
push(x);
}
else if(e[i]=='+' || e[i]=='*' || e[i]=='-' || e[i]=='/')
{
y=pop();
z=pop();
}
if(e[i]=='+')
{
value=y+z;
push (value);
}
else if(e[i]=='-')
{
value=y-z;
push (value);
}
else if(e[i]=='*')
{
value=y*z;
push (value);
}
else if(e[i]=='/')
{
value=y/z;
push (value);
}
}
getch();
}
/* This program generates errors, but I can't correct it . Thank you ery much for your help ! */
Mod Edit:Please
Thanks, gabehabe