Q. By making use of stacks, write an algorithm to determine whether the infix expression has balanced parenthesis or not.
Ans.
Algorithm parentheses is written below
This specific algorithm reads a source program and parses it to make sure all opening -closing parenthesis are systematically paired
1. loop (more data)
read (character)
if (character is not a closing parenthesis)
pushstack ( stack, character)
else
if (character is closing parenthesis)
popstack (stack, token)
while ( token is not an opening paranthesis)
popstack (stack, token)
endwhile end if
end if end loop
if (not emptystack (stack))
print (Error: opening parenthesis not matched)
end parseparens.