T The following is a detailed pseudocode solution to check a
Solution
Here is the code to be filled for you:
aStack createStack()
balancedSoFar = true
i = 0
while(balancedSoFar and i < length of aString)
{
ch = character at position i in aString
++i
//Push an open brace
if(ch is \'(\')
aStack.push(\'(\')
//Close brace
else if(ch is \')\')
if(!aStack isEmpty()) //Pop a matching open string.
aStack.pop()
else //No matching open brace.
balancedSoFar = false
//Ignores all characters other than braces
}
if(balancedSoFar and aStack.isEmpty())
aString has balanced braces
else
aString does not have balanced braces.
