Page 72 - DCAP605_ADVANCED_DATA_STRUCTURE_AND_ALGORITHMS
P. 72
Unit 3: Stacks
break; Notes
}
}
push(&stack, infix[i]);
}
else if (infix[i] == ‘)’) /* if current operator is right parenthesis */
{
while (1)
{
top_ch = stackTop(&stack); /* get tos */
if ( top_ch == ‘\0’ ) /* no stack left */
{
printf(“\nInvalid infix expression\n”);
/*print_msg();*/
exit(1);
}
else
{
if ( top_ch != ‘(‘ )
{
postfix[j++] = top_ch;
pop(&stack);
}
else
{
pop(&stack);
break;
}
}
}
continue;
}
}
}
postfix[j] = ‘\0’;
}
int isOperator(char c) /* determine if c is an operator */
{
if ( c == ‘+’ || c == ‘-’ || c == ‘*’ || c == ‘/’ || c == ‘%’ || c == ‘^’ )
return 1;
LOVELY PROFESSIONAL UNIVERSITY 67