Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(C++) 1) Using STL stack class, implement in C++ the following pseudocode function checkBraces(aString: string) that checks for balanced braces { } in a given

(C++)

1) Using STL stack class, implement in C++ the following pseudocode function checkBraces(aString: string) that checks for balanced braces { } in a given string / arithmetic expressions. Write a main() program to test the function.

2) 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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Transactions On Large Scale Data And Knowledge Centered Systems X Special Issue On Database And Expert Systems Applications Lncs 8220

Authors: Abdelkader Hameurlain ,Josef Kung ,Roland Wagner ,Stephen W. Liddle ,Klaus-Dieter Schewe ,Xiaofang Zhou

2013th Edition

3642412203, 978-3642412202

More Books

Students also viewed these Databases questions

Question

i need 6 9 7 .

Answered: 1 week ago