Write Non Recursive Function Uses Stack Reverse Characters String Function S Prototype Str Q37143496

Write a non-recursive function that uses a stack to reverse thecharacters in a string. the function’s prototype is stringreverse(const string& s);

Note: I need help to write out this problem in C++ whileusing Visual Studio 2017


Solution


#include <iostream>#include <string>#include <stack>using namespace std;string reverse(const string &s);int main() { string s; cout << “Enter a string: “; getline(cin, s); cout << reverse(s) << endl; return 0;}string reverse(const string &s) { string result = “”; stack<char> st; for (int

OR
OR

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.