- Write recursive and non-recursive functions that check parenthesis in a string.
Input string: (a(b(c)d)e)
Since this smells lots of homework, I'll give you no code.
But, it's not complex.
0) Create a integer counter , set to zero.
1) Loop through each character in the string (a
foreach loop is perfect for this)
1.0) If the character is a '(', increment the count by one
1.1) If the character is a ')', decrement the count by one
2) After the loop, check the count - if it is zero, all brackets match.
I wouldn't use recursion for this. It's a sledgehammer to crack a simple nut...
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)