So i have this reverse polish notation program i have to do for class which ask the user for a postfix expression .
for example the user would input a b + c d - * , the program at the end converts it into
((a + b) * (c - d)) But this is not my problem.
So my question is how do you push a b + c d - * which is one whole string, one element at a time into a stack. Professor also said the input has a space between each element when it is stored in the string.
the output would look like a b + c d - * taking up one stack.
I need it to be a b + c d - * taking up 7 stacks.
There was some basic code in class I'm using as a skeleton to write the program, If possible would like to modify it to fit what I need.
#include <iostream>
#include <string>
using namespace std;
typedef string stack_element;
class stack_node
{
public:
stack_element data;
stack_node *next;
};
class stack
{
public:
stack();
~stack();
stack_element & top();
void pop();
void push(const stack_element &);
void print();
private:
stack_node *s_top;
};
stack::stack()
{
s_top=0;
cout<<"Inside Default Constructor\n";
}
void stack::push(const stack_element & item)
{
cout<<"Inside push \n";
stack_node *p = new stack_node;
p->data = item;
p->next = 0;
if (s_top == 0)
{
s_top = p;
}
else
{
p->next = s_top;
s_top = p;
}
}
int main()
{
string input;
cout<<"enter an input:";
cin>>input;
S.push(input);
}