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.
Get Free Quote!
292 Experts Online