Question: Modify the given pseudocode to check if different types of braces, such as { }, ( ), [ ], match correspondently in order. And write

Modify the given pseudocode to check if different types of braces, such as { }, ( ), [ ], match correspondently in order. And write an enhanced function checkAllTypeBraces(aString: string) in C++, including a main() function to test it.

// Checks the string aString to verify that braces match.

// Returns true if aString contains matching braces, false otherwise.

checkBraces(aString: string): boolean {

aStack = a new empty stack

balancedSoFar = true

i = 0

// Tracks character position in string

while (balancedSoFar and i < length of aString)

{ ch = character at position i in aString

i++

// Push an open brace

if (ch is a '{')

aStack.push('{')

// Close brace

else if (ch is a '}')

{ if (!aStack.isEmpty())

aStack.pop()

// Pop a matching open brace

else

// No matching open brace

balancedSoFar = false

} // Ignore all characters other than braces

} if (balancedSoFar and aStack.isEmpty())

aString has balanced braces

else

aString does not have balanced braces

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!