#6 Write an object oriented C++ program to translate an infix expression to post
ID: 3570797 • Letter: #
Question
#6 Write an object oriented C++ program to translate an infix expression to postfix (Reverse Polish notation. Your input directions should be very clear, perhaps showing an example input. The code should be able to handle nested parentheses.Explanation / Answer
# include # include # include # include struct node { char data; node *next; }; node *top=NULL; node *bottom=NULL; node *entry; node *last_entry; node *second_last_entry; void push(constchar); constchar pop( ); void infix_to_postfix(constchar *); int main( ) { clrscr( ); char Infix_expression[100]={NULL}; coutInfix_expression; infix_to_postfix(Infix_expression); getch( ); return 0; } /*************************************************************************//*************************************************************************///------------------------ Function Definitions -----------------------///*************************************************************************//*************************************************************************//*************************************************************************///----------------------------- push(const char) ----------------------///*************************************************************************/void push(constchar Symbol) { entry=new node; if(bottom==NULL) { entry->data=Symbol; entry->next=NULL; bottom=entry; top=entry; } else { entry->data=Symbol; entry->next=NULL; top->next=entry; top=entry; } } /*************************************************************************///-------------------------------- pop( ) -----------------------------///*************************************************************************/constchar pop( ) { char Symbol=NULL; if(bottom==NULL) coutnext=NULL; } return Symbol; } /*************************************************************************///--------------------- infix_to_postfix(const char *) ----------------///*************************************************************************/void infix_to_postfix(constchar *Infix) { char Infix_expression[100]={NULL}; char Postfix_expression[100]={NULL}; strcpy(Infix_expression,"("); strcat(Infix_expression,Infix); strcat(Infix_expression,")"); char Symbol[5]={NULL}; char Temp[5]={NULL}; for(int count=0;countRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.