Click here to Skip to main content
15,888,351 members

Comments by Nandini Sathyan S (Top 6 by date)

Nandini Sathyan S 8-Jul-21 3:22am View    
Sure
Nandini Sathyan S 8-Jul-21 2:17am View    
Thank you so much! I have learned to debug as u suggested
Nandini Sathyan S 26-Apr-21 23:16pm View    
Thank You!
Nandini Sathyan S 30-Oct-20 10:54am View    
#include <iostream>
using namespace std;
class Stack{
public:
char arr[10];
int top=-1;
int push(char);
char pop();
};
class Evaluate_infix{
char infix[20];
char postfix[20];
Stack operators;
Stack operand;
public:
void printPostfix();
void readInfix();
void Infix_Postfix();
void postfix_eval();
int precedence (char);
};
void Evaluate_infix::readInfix()
{

cout<<"\nEnter the infix expression : ";
cin>>infix;

}
void Evaluate_infix::Infix_Postfix()
{
int i=0,k=0;
while(infix[i]!='\0')
{
if((int)infix[i]>=49 && (int)infix[i]<=57)
{
postfix[k]=infix[i];
i++;
k++;
}
else if(infix[i]=='(' || infix[i]=='{' || infix[i]=='[')
{
operators.push(infix[i]);
i++;
}
else if(infix[i]==')' || infix[i]=='}' || infix[i]==']')
{
if(infix[i]==')')
{
while(operators.arr[operators.top]!='(')
{
postfix[k]=operators.pop();
k++;
}
operators.pop();
i++;

}
if(infix[i]==']')
{
while(operators.arr[operators.top]!='[')
{
postfix[k]=operators.pop();
k++;
}
operators.pop();
i++;
}

if(infix[i]=='}')
{
while(operators.arr[operators.top]!='{')
{
postfix[k]=operators.pop();
k++;
}
operators.pop();
i++;
}
}
else
{
if(operators.top==-1)
{
operators.push(infix[i]);
i++;
}

else if( precedence(infix[i]) <= precedence(operators.arr[operators.top])) {
postfix[k]=operators.pop();
k++;

while(precedence(operators.arr[operators.top]) == precedence(infix[i])){
postfix[k]=operators.pop();
if(operators.top < 0) {
break;
}
}
operators.push(infix[i]);
i++;
}
else if(precedence(infix[i]) > precedence(operators.arr[operators.top])) {
operators.push(infix[i]);
i++;
}
}
}
while(operators.top!=-1)
{
postfix[k]=operators.pop();
k++;
}

}

int Evaluate_infix::precedence ( char ch )
{
if(ch == '^')
{
return(3);
}
if(ch == '+' || ch =='-')
{
return(2);
}

if(ch == '*' || ch =='/')
{
return(1);
}

if(ch == '(')
{
return(0);
}

return 0;
}

int Stack::push(char item)
{
if(top==19)
{
cout<<"Overflow";
return -1;
}
else{
top=top+1;
arr[top]=item;
return 0;
}
}
char Stack::pop()
{
if(top==-1)
{
cout<<"Underflow";
return-1 ;
}
else{
int item=arr[top];
top=top-1;
return item;
}
}
void Evaluate_infix::printPostfix()
{

cout<<"The converted postfix string is : "<<postfix;

}
void="" evaluate_infix::postfix_eval()
{
="" int="" i="0;
" char="" a,b,res;
="" while(postfix[i]!="\0" )
="" {=""
="" if((int)postfix[i]="">=49 && (int)postfix[i]<=57)
{
operand.push(postfix[i]);
i++;
}
else if( postfix[i]=='+')
{
a=operand.pop();;
a=a-48;
Nandini Sathyan S 30-Oct-20 10:53am View    
Can I upload the full code then? I hope u may understand@Rick York