I'm Too Stupid, Please Help!!!

T

Twizster

I want to design an algorythm that will test proper nesting of open and
closing chars such as brackets and parens, and then get the appropriate
position of the closeing char. For instance:

In these expamples I want to know which paren closes the first paren
(( ) ( ))
or
(( ))
or the twist
(( )) ( )
 
J

John Spencer

Example 1: Last paren closes the first paren
Example 2: Last paren closes the first paren
Example 3: fourth paren closes the first paren

Basically add 1 for each opening paren and subtract one for each closing
paren. When the result is zero the closure takes place.

For subsequent nested positions
2nd paren is closed when the total becomes 1
3rd set of nested parens is closed when the total becomes 2

1 is closed by zero
2 is closed by one
3 is closed by two



'====================================================
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
'====================================================
 
Top