stack operation

Page 1 of 1

1 Replies - 2187 Views - Last Post: 22 September 2009 - 01:33 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=127260&amp;s=9a08333d757c47bc42b33df1a3c99a7a&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

#1 nmettu

Reputation: 0
• Posts: 6
• Joined: 22-September 09

stack operation

Posted 22 September 2009 - 12:54 AM

hi
can anyone help me wth the answer for this question

Using the stack operations push and pop, write an algorithm to verify proper nesting of brackets in an expression that uses three types of brackets – ( ), [ ] and { }.
Is This A Good Question/Topic? 0

Replies To: stack operation

#2 aks29921

• D.I.C Regular

Reputation: 116
• Posts: 345
• Joined: 24-August 09

Re: stack operation

Posted 22 September 2009 - 01:33 AM

1. get the input expression
2. scan it form left to right one character at a time
3. when you encounter an opening bracket, i.e. ( , { or [, push it onto a stack
4. when you encounter a closing bracket, i.e. ) , } or ], pop from the top of stack. if for all such closing brackets, you always encounter the correct corresponding opening bracket after pop operation (i.e. ( for ), { for } and [ for ]) then the nesting of brackets is proper.
also, when your expression is finished (has been scanned fully from left to right), your stack should be empty(i.e. top of stack should be null)

now implement this algo