On Wed, 07 Oct 2009, Chris Burke wrote:
> How to check if a string has balanced [] {} ()?
> 
> Any pair by itself is easy enough, but I want to check all three balance 
> together, e.g.
> 
>    ...[(])...
> 
> would fail. Assume there are no character strings.
> 
> Ideally, I'd like a result of
> 
>    0 = balanced
>    1 = balanced so far, but some closing delimiters to come
>    2 = unbalanced (and broken)

I guess you can push { [ ( into stack while scanning. On seeing } ] )
pop stack and fail if the top of stack is not compatible brackets.

-- 
regards,
====================================================
GPG key 1024D/4434BAB3 2008-08-24
gpg --keyserver subkeys.pgp.net --recv-keys 4434BAB3
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to