Hi all...
How can I control any postfix expression is valid or not???
I controlled it using a stack(the code is below) and it worked but I 'm using the stack again after clearing it for evaluation the postfix expression to the infix expression.I'm using the stack twice and I didn't find it efficient.
Is there a more efficient way to control wheter the postfix expression is valid???
for(i = 0; postfix[i] != '\0'; i++)
{
if(postfix[i] != '+' && postfix[i] != '-' && postfix[i] != '/' && postfix[i] != '*')
{
Push(postfix[i],&myStack);/*If it is not an operator, push it to the stack...*/
}
else
{
if(StackSize(&myStack) >= 2)
Pop(&num2,&myStack);
else
{
printf("Invalid postfix expression\n");
ClearStack(&myStack);
break;
}
}
}