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
The two pointers per number of a doubly linked list prepare programming quite easy. Singly linked lists as like the lean sisters of doubly linked lists. We need SItem to consider t

what is frequency count with examble? examble?

I need to know about data structure and algorithms. can you help me?

A LGORITHM (Deletion of an element from the linked list) Step 1  Begin Step 2  if the list is empty, then element cannot be deleted Step 3  else, if the element to be del

An interesting application or implementation of trees is the playing of games such as tie-tac-toe, chess, nim, kalam, chess, go etc. We can depict the sequence of possible moves

Simplifying Assumptions of wire frame representation Neglect colour - consider Intensity: For now we shall forget about colour and restrict our discussion just to the intensi

The two famous methods for traversing are:- a) Depth first traversal b) Breadth first

Write a detailed description of a function that takes in an integer as an argument, then prints out the squares of all positive integers whose squares are less than the input. (The


Each of the comparison in the binary search decrease the number of possible candidates where the key value can be searched by a factor of 2 as the array is divided into two halves