In this lab, you will implement some useful functions using stacks. In particular, you will write functions using stacks for the following purposes: Reverse a string. Check whether a string is a palindrome. Check whether parenthesis and brackets are balan

computer science

Description

In this lab, you will implement some useful functions using stacks. In particular, you will write functions using stacks for the following purposes: Reverse a string. Check whether a string is a palindrome. Check whether parenthesis and brackets are balanced in a string. Reverse a string First, you will write a function that uses a stack to reverse a string. Download theStack class and begin work on a function called reverseString just before the main function. To begin, identify the output type and the input type(s), then write your function prototype. The function should take in a string and output the string in reverse. Next, create a stack of chars. Loop over the input string and push each char to the stack as you go. Now create an output string and initialize it to the empty string "". Using a while loop, remove each char from the stack and add it to the string using the string::push_back(char c) function (i.e. str.push_back(stack.top()). Finally, return the output string.


Related Questions in computer science category


Disclaimer
The ready solutions purchased from Library are already used solutions. Please do not submit them directly as it may lead to plagiarism. Once paid, the solution file download link will be sent to your provided email. Please either use them for learning purpose or re-write them in your own language. In case if you haven't get the email, do let us know via chat support.