Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <conio>
- class ListStack
- {
- private:
- struct node
- {
- int num;
- node *next;
- }*top;
- int operand_count;
- public:
- ListStack()
- {
- top=NULL;
- }
- int push(int);
- int pop();
- void display();
- void get_expression();
- int get_value(int);
- };
- int ListStack::push(int c)
- {
- node *temp;
- temp = new node;
- temp->num=c;
- temp->next=top;
- top=temp;
- return c;
- }
- int ListStack::pop()
- { int c;
- if(top==NULL)
- cout<<"Stack UnderFlow"<<endl;
- else
- {
- node *temp;
- temp=top;
- cout<<"deleted Number from the stack = ";
- c=top->num;
- top=top->next;
- //return (temp->num);
- delete temp;
- return (c);
- }
- }
- void ListStack::display()
- { node*temp;
- temp=top;
- while(temp!=NULL)
- {
- cout<<"n"<<temp->num<<endl;
- temp=temp->next;
- }
- }
- int ListStack::get_value(int c)
- { int operand_count;
- cout<<"how many number of operands you have?";
- cin>>operand_count;
- int numeric_array[5];
- int i;
- for (i=0;i<=operand_count;i++)
- {
- cout<<"Enter Value: ";
- cin>>numeric_array[i];
- //return numeric_array;
- }
- }
- void ListStack::get_expression()
- {
- char save;
- int i=0;
- int first_operand, second_operand, result;
- char postfix_array[50], No_operator[50];
- cout<<"Enter the numeric Postfix expression: ";
- cin.getline(postfix_array,50);
- while (postfix_array[i]!='