First of all make sure the given equation is valid i.e. number of
opening brackets is equal to number of closing bracket.

Then remember that the closing bracket will belong to nearest opening
bracket of that type.

   Read the equation from starting to end, when you will encounter the
opening bracket i.e. { set a counter with initial value equal to 0,
move to next position then read that value if it is opening bracket
{ then increment the counter variable and if it is closing bracket
then decrement the counter, position at which the value of counter
becomes negative it the position for its closing bracket & for other
values encountered while reading the equation just skip and move to
next value.




On Oct 29, 1:50 pm, Gourav <[email protected]> wrote:
> Hi All,'
>    I was just making some program then i am unable to find following
> Query..
>
> Make a program in which Finding the position of opening and closing
> brackets of { }.
> Q..... { () { [ ( ) ] } { ( ) } }
> Then answer should be
> ___________________________________________
> Bracket { openning at 1 and closing at 14
> Bracket ( openning at 2 and closing at 3
> Bracket { openning at 4 and closing at 9
> Bracket [ openning at 5 and closing at 8
> Bracket ( openning at 6 and closing at 7
> and so on
> ___________________________________________

Reply via email to