Infix expression has balanced parenthesis or not, Data Structure & Algorithms

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.

Posted Date: 7/13/2012 2:41:38 AM | Location : United States







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

Write discussion on Infix expression has balanced parenthesis or not
Your posts are moderated
Related Questions
Question 1 . Give the structure of PL/SQL Blocks and explain Question 2 . Differentiate between PL/SQL functions and procedures Question 3 . Explain the following Par

the deference between insertion,selection and bubble sort

Write an algorithm using pseudocode which takes temperatures input over a 100 day period (once per day) and output the number of days when the temperature was below 20C and the num

Explain binary search with an example

The following are several operations on a AA-tree: 1. Searching: Searching is done using an algorithm which is similar to the search algorithm of a binary search tree. 2. Ins

Write down the algorithm of quick sort. An algorithm for quick sort: void quicksort ( int a[ ], int lower, int upper ) {  int i ;  if ( upper > lower ) {   i = split ( a,

what is alphanumerical code

What are the expression trees? Represent the below written expression using a tree. Give a relevant comment on the result that you get when this tree is traversed in Preorder,

multilist representation of graph

Following are some of the drawback of sequential file organisation: Updates are not simply accommodated. By definition, random access is impossible. All records should be