Solution for Problem 1 (Infix, postfix and prefix) a. Postfix: ab+c+d+ ab+cde-/* b. Prefix: *2+34 *+ab/c-de c. Infix: a*b-(c+d) (a+b)*(c-(d-e)) ================================================================================ Solution for Problem 2 (Language recognition with stacks) #include #include #include class mystack { struct link { char data; link* next; link(char Data, link* Next) { data=Data; next=Next; } } * head; public: mystack(){head=NULL;} ~mystack(); void Push(char Data){ head=new link(Data,head); } char Pop(); bool StackIsEmpty(); }; char mystack::Pop(){ if(head==0) return 0; char result=head->data; link* oldhead=head; head=head->next; delete oldhead; return result; } bool mystack::StackIsEmpty(){ if (head==0) return 1; else return 0; } mystack::~mystack(){ link* cursor=head; while(head){ cursor=cursor->next; delete head; head=cursor; } } main(){ mystack S; char str[100], stackpop; int i=0,flag=1; cout<<"Input a string: "; cin>>str; cout< #include int precedence(char ch){ if (ch=='+'||ch=='-') return 1; if (ch=='*'||ch=='/') return 2; return -1; } class mystack { struct link { int data; link* next; link(int Data, link* Next) { data=Data; next=Next; } } * head; public: mystack(){head=NULL;} ~mystack(); void Push(int Data){ head=new link(Data,head); } int Pop(); bool StackIsEmpty(); int GetStackTop(); }; int mystack::Pop(){ if(head==0) return 0; int result=head->data; link* oldhead=head; head=head->next; delete oldhead; return result; } bool mystack::StackIsEmpty(){ if (head==0) return 1; else return 0; } int mystack::GetStackTop(){ if(head==0) return 0; return head->data; } mystack::~mystack(){ link* cursor=head; while(head){ cursor=cursor->next; delete head; head=cursor; } } class InfixCalc { mystack S; char PE[100]; char str[100]; public: InfixCalc(char exp[]); ~InfixCalc(); void in2post(); int calc(); }; InfixCalc::InfixCalc(char exp[]){ int i=0; while(exp[i]!=0){ str[i]=exp[i]; i++; } str[i]=0; } void InfixCalc::in2post(){ int i=0; int j=0; char ch; while(str[i]!=0){ ch=str[i]; switch(ch){ case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': PE[j]=ch; j++; break; case '(': S.Push(ch); break; case ')': while(S.GetStackTop()!='('){ PE[j]=S.Pop(); j++; } S.Pop(); break; case '+': case '-': case '*': case '/': while(!S.StackIsEmpty() && (S.GetStackTop()!='(') &&(precedence(ch)<=precedence(S.GetStackTop()))){ PE[j]=S.Pop(); j++; } S.Push(ch); break; } i++; } while(!S.StackIsEmpty()){ PE[j]=S.Pop(); j++; } PE[j]=0; cout<<"The Postfix is :"<='0')&&(ch<='9')){ value=ch-'0'; S.Push(value); } else { Operand2=S.Pop(); Operand1=S.Pop(); switch(ch){ case '+': result=Operand1+Operand2; break; case '-': result=Operand1-Operand2; break; case '*': result=Operand1*Operand2; break; case '/': if (Operand2==0){ cout<<"Cannot divided by 0."<>str; cout<