After this loop , stack contains unbalanced part of expression , i . e . , expression of the form " } } . . } { { . . { "
Stack < char > s = new Stack < char > ( ) ; for ( int i = 0 ; i < len ; i ++ ) { char c = expr [ i ] ; if ( c == ' } ' && s . Count > 0 ) { if ( s . Peek ( ) == ' { ' ) { s . Pop ( ) ; } else { s . Push ( c ) ; } } else { s . Push ( c ) ; } }