write aprogram in c++ to read the tokens in one at a time ,if it is
integer,push it on stack, if it is binary operator, pop two elements
from the stack, apply the operator to the two elements and push the result back on the stack??
i need your help to me to solve this question and thanks for every body help me in solutoin
and this my tired
Sorry but i new !!
but was my tried simpleton ??
Code:
#include<iostream.h>
const int size=5;
void push(int[],int&,int);
void pop(int[],int&,int&);
void main()
{int stack[size],item,top=0,i;
for(i=0;i<size;i++)
{cout<<"Enter item"<<endl;
cin>>item;
push(stack,top,item);
}
for(i=0;i<size;i++)
{pop(stack,top,item);
int x; // x from type integer
if(item==x)
push(stack,top,item);
else
pop(stack,top,item);
}
for(i=0;i<size;i++)
{push(stack,top,item);
pop(stack,top,item);
}
}
void push(int stack[size],int&top,int item)
{if(top<size)
top++;
stack[top]=item;
else
cout<<"stack is FULL"<<endl;
}
void pop(int stack[top],int&top,int&item)
{if(top>0)
{item=stack[top];
top--;
}
else
cout<<"the stack is EMPTY"<<endl;
}
thank s