Whether the infix expression has balanced parenthesis or not, Data Structure & Algorithms

Using stacks, write an algorithm to determine whether the infix expression has balanced parenthesis or not

Algorithm parseparens

This algorithm reads a source program and parses it to make sure all opening -

closing parenthesis are 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.

 

Posted Date: 5/11/2013 1:30:26 AM | Location : United States





Thanks for suggesting me this answer, appreciate your knowledge. 

Posted by | Posted Date: 5/11/2013 1:31:02 AM


Related Discussions:- Whether the infix expression has balanced parenthesis or not, Assignment Help, Ask Question on Whether the infix expression has balanced parenthesis or not, Get Answer, Expert's Help, Whether the infix expression has balanced parenthesis or not Discussions

Write discussion on Whether the infix expression has balanced parenthesis or not
Your posts are moderated
Related Questions
Explain the array and linked list implementation of stack

Explain what are circular queues? Write down routines required for inserting and deleting elements from a circular queue implemented using arrays.           Circular queue:

compare and contrast the bubble sort,quick sort,merge sort and radix sort


This notation gives an upper bound for a function to within a constant factor. Given Figure illustrates the plot of f(n) = O(g(n)) depend on big O notation. We write f(n) = O(g(n))

how to define the size of array

HSV Colour Model Instead of a set of colour primaries, the HSV model uses colour descriptions that have a more intuitive appeal to a user. To give a colour specification, a use

what is queues? how it work? and why it used? i want an assignment on queue .....

Comp are two functions n 2    and  2 n  / 4  for distinct values of n.   Determine When s ec on d function b ec om es l a r g er th an f i r st functi

The number of leaf nodes in a complete binary tree of depth d is    2 d