postfix using arrays
Oct 20, 2012 at 5:33am UTC
HI i am doing a program which takes numbers from a user into postfix, using an array i cannot use the stack library. SO far i have the following i know i need to implement some cases for the +-*/ then popping them out. any help will be appreciated
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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
#include<iostream>;
#include<stdlib.h>;
using namespace std;
class stack
{
int stk[50],top;
public :
stack(){
topstack =-1;
}
void push(int x)
{
if (topstack>50)
{
cout<<"the stack is full" ;
return ;
}
stk[++topstack]=x;
}
void pop()
{
if (top<0)
{
cout<<"the stack is empty" ;
return ;
}
}
};
int main () {
int ch;
stack st;
while (1)
{
cout <<"\n Press 1 to push \n Press 2 to pop \n Press 3 to quit " ;
cin >>ch;
switch (ch)
{
case 1: cout<<"Enter Choice:" ;
cin>>ch;
st.push(ch);
break ;
case 2: st.pop();
break ;
case 3: exit(0);
}
return (0);
}
}
Topic archived. No new replies allowed.