Hello to you all ,
I am required to write a program which gets a Math Expression (without checking it is good) and put in Stack only the Brackets .
Implementation of Stack is One-Way Linked List Only.
Examples for Good/Bad Expressions :
(a*{b+c}-4/x +[e-5]) - GOOD
(5+} - BAD
(5+{6*)-2} - BAD
(5+z - BAD
I have build up a Mechanism which checks for each entered char (other than Enter Key and also using closing brackets such as ) or ] or } at the beginning of Expression) what type of bracket it is and pushes it into a stack (we must use LIFO technique for check legal Expression).
I thought of 2 cases :
first case : for each open bracket there is a closing one so i check top of stack to bottom of stack and carry on till i reach to middle .
second case : what happens if i have this sequence - ()[]{} - meaning i need to check top against the next , and so on (top of stack to bottom of stack will not help in this case)
I kinda stuck on Algorithm Think Phase :-)
Code Added . Any Ideas ?
Thank you , Yotam , Israel