Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program to convert infix string to postfix string using stakes. you has

ID: 3620801 • Letter: W

Question

Write a program to convert infix string to postfix string using stakes.
you has to implement :
1) a class to implement stack.
2) stack should be dynamically implemented.
3).Take an infix string in the main.
4).push the operators and parenthesis in the string to the stack according the rules of
conversion from infix to postfix.
5).Using rules of conversion and save the converted postfix string in a new string
variable in main.

Don't use any global variable.All work should be performed using one class with the name DSTACK and main.
My class is :
class dstack
{
private:
struct node
{
char ch;
node *ptr;
}
node *top;
public:
dstack();
void push(char ch);
void pop(char ch);
void display();
};

Explanation / Answer

Dear, Here is the code.. #ifndef STACKNODE_H #define STACKNODE_H template class Stack;//forward declaration template class StackNode { friend class Stack; public: StackNode(const T &,StackNode *); T getData()const; //set point to next stack node void setNextPtr(StackNode *nPtr) { nextPtr=nPtr; }//end function StackNode *getNextPtr()const { return nextPtr; } private: T data; StackNode *nextPtr; }; //Member function definitions template StackNode::StackNode(const T &d,StackNode *ptr) { data=d; nextPtr=ptr; }//end constructor //getdata template StackNode::getDta()const { return data; }//end function getData #endif #ifndef STACK_H #define STACK_H #include using std::cout; #include #include "StackNode.h" template class Stack { public: Stack(); ~Stack(); void push(T &); T pop(); bool isEmpty()const; T stackTop()const; void print()const; StackNode *getTopPtr()const { return topPtr; } private: StackNode *topPtr; }; //end class template stack //member function definitions template Stack ::Stack() { topPtr=0; } template Stack::~Stack() { StackNode *tempPtr,*currentPtr=topPtr; while(currentPtr!=0) { tempPtr=currentPtr; currentPtr=currentPtr->getNextPtr(); delete tempPtr; }//end while }//end destructor //push node template void Stack::push(T &d) { StackNode *newPtr=new StackNode(d,topPtr); topPtr=newPtr; }//end function push //pop node template T Stack::pop() { StackNode *tempPtr=topPtr; topPtr=topPtr->nextPtr; T poppedValue=tempPtr->data; delete tempPtr; return poppedValue; }//end function pop //is stack empty template bool Stack::isEmpty()const { return topPtr==0; }//end function template T Stack::stackTop()const { return !isEmpty()?getTopPtr()->getData():static_cast(0); }//end function stackTop //display stack template void Stack::print()const { StackNode*currentPtr=topPtr; if(isEmpty()) cout
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote