1 Replies - 1845 Views - Last Post: 22 September 2009 - 01:33 AM Rate Topic: -----

#1 nmettu  Icon User is offline

  • New D.I.C Head

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

stack operation

Post icon  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  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 84
  • View blog
  • Posts: 230
  • 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
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1