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
Searching is the procedure of looking for something: Finding one piece of data that has been stored inside a whole group of data. It is frequently the most time-consuming part of m

how to implement multiple stack using single dimension array in c

Q. Describe the term array.  How do we represent two-dimensional arrays in memory?  Explain how we calculate the address of an element in a two dimensional array.

Method to measure address of any element of a matrix stored in memory. Let us consider 2 dimensional array a of size m*n further consider that the lower bound for the row index

Board coloring , C/C++ Programming

If preorder traversal and post order traversal is given then how to calculate the pre order traversal. Please illustrate step by step process

Consider a linked list of n elements. What is the time taken to insert an element after an element pointed by some pointer? O (1)

write an algorithm to delete an element x from binary search with time complex

Q. Explain the various memory allocation strategies.                                                            Ans. M e m ory Allocation Strategies are given as follow

Run time complexity of an algorithm is depend on