What is the errors here? correct it please //Evaluate the postfix expression //623+-382/+*2&3+ #include #include #include using namespace std; void push(long int character); long int postfix_evaluation(); int pop(); int isEmpty(); int top; long int stack[50]; char postfix_expression[50]; int main() { long int evaluated_value; top = -1; cout<<"\nEnter an Expression in Postfix format:\t"; cin>>postfix_expression; cout<<"\nExpression in Postfix Format: \t"<= '0') { push(postfix_expression[count] - '0'); } else { x = pop(); y = pop(); switch(postfix_expression[count]) { case '+': temp = y + x; break; case '-': temp = y - x; break; case '*': temp = y * x; break; case '/': temp = y / x; break; case '&': temp = pow(y, x); break; case '^': temp = pow(y, x); break; default: cout<<"Invalid"; } push(temp); } } value = pop(); return value; } void push(long int character) { if(top > 50) { cout<<"Stack Overflow\n"; exit(1); } top = top + 1; stack[top] = character; } int pop() { if(isEmpty()) { cout<<"Stack is Empty\n"; exit(1); } return(stack[top--]); } int isEmpty() { if(top == -1) { return 1; } else { return 0; } }
What is the errors here? correct it please
//Evaluate the postfix expression
//623+-382/+*2&3+
#include<iostream>
#include<cmath>
#include<stdlib.h>
using namespace std;
void push(long int character);
long int postfix_evaluation();
int pop();
int isEmpty();
int top;
long int stack[50];
char postfix_expression[50];
int main()
{
long int evaluated_value;
top = -1;
cout<<"\nEnter an Expression in Postfix
format:\t";
cin>>postfix_expression;
cout<<"\nExpression in Postfix Format:
\t"<<postfix_expression<<endl;
evaluated_value = postfix_evaluation();
cout<<"\nEvaluation of Postfix Expression:
\t" <<evaluated_value<<endl;
system("pause");
return 0;
}
long int postfix_evaluation()
{
double x, y, temp, value;
int count;
for(count = 0; count <
strlen(postfix_expression); count++)
{
if(postfix_expression[count] <= '9' &&
postfix_expression[count] >= '0')
{
push(postfix_expression[count] - '0');
}
else
{
x = pop();
y = pop();
switch(postfix_expression[count])
{
case '+': temp = y + x;
break;
case '-': temp = y - x;
break;
case '*': temp = y * x;
break;
case '/': temp = y / x;
break;
case '&': temp = pow(y, x);
break;
case '^': temp = pow(y, x);
break;
default: cout<<"Invalid";
}
push(temp);
}
}
value = pop();
return value;
}
void push(long int character)
{
if(top > 50)
{
cout<<"Stack Overflow\n";
exit(1);
}
top = top + 1;
stack[top] = character;
}
int pop()
{
if(isEmpty())
{
cout<<"Stack is Empty\n";
exit(1);
}
return(stack[top--]);
}
int isEmpty()
{
if(top == -1)
{
return 1;
}
else
{
return 0;
}
}
Step by step
Solved in 2 steps