This can be done using Stack .

For example :- you have got the pattern :-

0 1 2 3 4 5 6 7 8 9 10 11
( ( ) ( ( ) ( ( ) ) (  )   ... this pattern is wrong the faulty index
is at index 3 .


void MatchingBracket( char *str )
{
  while ( str[i++] != '\0' )
  {
     if ( str[i] == '(') push(i); // If '(' is encountered the push
the index
       else if (str[i]== ')') pop (); // if ')' the pop the stack
   }
  // if stack empty the no suck index else print the top of the stack

  if(top>=0) printf("%d ",stack[top]);
}

It will give the faulty index as 3rd one .




Note :- This code is not tested ....

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to