Explore BrainMass

C++ code to test for matching brackets and palindromes

Please help me in writing the code to test the stack class, and enhancing and testing the queue class.

1. Test the stack class by determining if the following strings have matching open and closing () and/or {} and/or [] :

The fourth one is the only one that should not have matching pairs.

2. Please complete the Queue class including following functions:

Write the code to test the queue class by determining if the following strings are char-by-char palindromes:

Please refer to the attached files to use for the input.


Solution Preview

Please find the corrected version of your main.cpp along with requested functionality addition attached as 502363.cpp . It has been tested compiling without any warnings and errors using g++ version 4.3.4 using the command "g++ -Wall 502363.cpp" and has been tested with your provided input files.

To test the code, place the executable in same directory as your input files and run it from there. Output generated is pasted below for your verification.

-------------- Output begins ------------------

Testing ...

Solution Summary

Attached code has been tested compiling and working fine, using the GNU C++ compiler g++ version 4.3.4 . Also, it tests for palindromes via two different implementations. Please note that the attached code is primarily for your understanding and you will need to tweak it (remove/reword comments/code as needed, decide which palindrome testing you want to go ahead with, have a uniform style of comments and coding) in case you plan to use it anywhere.