#include <string>#include <iostream>#include <vector>using namespace std;// PrintStack(vector <char> stack)// Prints the contents of stackvoid PrintStack(vector <char> stack){ // Loop through each character in the stack and print them preceded by their index for(int i = 0; i < stack.size(); i++) cout << i << ") " << stack[i] << endl;}// void ReverseStack(vector <char> *stack)// Goes through each item in the stack and re-adds them in reversevoid ReverseStack(vector <char> *stack){ // Make a temporary copy of the stack, then clear the real one vector <char> tmp = *stack; stack->clear(); // Loop through all items in the temporary stack in reverse, then add them to the real stack for(int i = 0; i < tmp.size(); i++) stack->push_back(tmp[(tmp.size() - 1) - i]);}int main(){ // Create the stack vector <char> stack; // Add an item to the stack string str = "racecar"; cout << "Analyzing string: " << str << endl; // Loop through the characters in str for(int i = 0; i < str.size(); i++) { // Strip out the character and add to stack char *ch = new char; sprintf(ch, str.substr(i, 1).c_str()); stack.push_back(*ch); } // Output the current stack cout << "Current stack is:\n"; PrintStack(stack); cout << endl; // Reverse the stack ReverseStack(&stack); // Print the new stack cout << "The stack is now:\n"; PrintStack(stack); // Wait for a key to be pressed before returning. getchar(); return 1;}OUTPUT:Analyzing string: racecarCurrent stack is:0) r1) a2) c3) e4) c5) a6) rThe stack is now:0) r1) a2) c3) e4) c5) a6) rOUTPUT2:Analyzing string: RandomWordCurrent stack is:0) R1) a2) n3) d4) o5) m6) W7) o8) r9) dThe stack is now:0) d1) r2) o3) W4) m5) o6) d7) n8) a9) R