```
/*Gaspan, Mark Cristian
Garrote, Sheryn
Genio, Precy Lou
Hersia, Sarah
Espiritu,
*/
#include<iostream.h>
#include<conio.h>
#include<string.h>
struct node{
char *data;
node *next;
}*postfix,*infix,*stack,*ptr1,*temp,*bptr,*delnode,*head,*headpost;
void main(){
char *dataned[30];
int i=0,e;
int lenstr;
infix=new node;
postfix=new node;
stack=new node;
temp=new node;
headpost=postfix;
ptr1=infix;
head=infix;
clrscr();
cout<<"Converting Infix to Postfix\n";
cout<<"Input the Infix:\n\t->";
do{
cin>>dataned[i];
i=i+1;
}while(dataned[i]==" ");
for(e=0;e<i;e++){
ptr1->data=dataned[e];
ptr1=ptr1->next;
}
ptr1=head;
do{
if(ptr1->data!=")"||ptr1->data!="("||ptr1->data!="+"|| //Input the variable
ptr1->data!="-"||ptr1->data!="*"||ptr1->data!="/"|| //to the postfix
ptr1->data!="^"){
postfix->data=ptr1->data;
postfix=postfix->next;
}else{//Input the operator to the stack
if(stack==NULL){
temp->data=ptr1->data;
temp->next=stack;
stack=temp;
}else{
//comparing the precedence
if( ((stack->data=="+"||ptr1->data=="-")&&
(stack->data=="-"||ptr1->data=="+"))||
((stack->data=="/"||ptr1->data=="*")&&
(stack->data=="*"||ptr1->data=="/")) ){
postfix->data=stack->data;
postfix=postfix->next;
temp=stack->next;
delete stack;//delete the node
stack=temp;
}else if((stack->data=="/"||stack->data=="*")&&
(ptr1->data=="+"||ptr1->data=="-")){
postfix->data=stack->data;
postfix=postfix->next;
temp=stack->next;
delete stack;
stack=temp;
temp->data=ptr1->data;
temp->next=stack;
stack=temp;
}else if((stack->data=="+"||stack->data=="-")&&
(ptr1->data=="*"||ptr1->data=="/")){
postfix->data=ptr1->data;
postfix=postfix->next;
}else if(ptr1->data=="^"&&stack->data!="("){
stack->data=ptr1->data;
stack=stack->next;
}else if(ptr1->data=="("){
temp->data=ptr1->data;
temp->next=ptr1;
ptr1=temp;
}else if(ptr1->data==")"){
postfix->data=stack->data;
bptr=stack->next->next;
delnode=stack->next;
delete stack;
delete delnode;
stack=bptr;
}else{
postfix->data=stack->data;
postfix=postfix->next;
delnode=stack->next;
delete stack;
stack=delnode;
}
}
}
}while(ptr1!=NULL);
cout<<endl;
for(postfix=headpost;postfix!=NULL;postfix=postfix->next){
cout<<postfix->data;
}
getch();
}
```