(Reversing a string with Iterators using Recursion) Write a recursive version of Exercise 18.21.

What will be an ideal response?


```
// Program recursively prints a string backward.
#include
#include
using namespace std;

void printBackward( const string::reverse_iterator,
string::reverse_iterator ); // prototype

int main()
{
string s;

cout << "Enter a string: ";
getline( cin, s );

// reverse_iterator r points
// one location beyond the end of the reverse string
string::reverse_iterator r = s.rend();

// call recursive function printBackward
printBackward( s.rbegin(), r - 1 );
cout << endl;
} // end main

// function to print the reverse string
void printBackward( const string::reverse_iterator s,
string::reverse_iterator rb )
{
// if the end is reached, return
if ( rb == s - 1 )
return;

// recursive call to go through the string
printBackwards( s, rb - 1 );
cout << *rb;
} // end function printBackward
```
Enter a string: print this backward
drawkcab siht tnirp

Computer Science & Information Technology

You might also like to view...

If you do not see the Apply Styles panel, click View on the menu bar, then click Reset Workspace Layout.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology

Some SmartArt graphic layouts are limited by the number of ____________________ they can accommodate.

Fill in the blank(s) with the appropriate word(s).

Computer Science & Information Technology

A decision tree is read from left to right, with the conditions along the various branches and the actions at the far left.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology

What allows you to make voice calls over a computer network?

A. Satellites B. Tunneling C. Encryption D. VoIP E. What is the most common VoIP application protocol? F. SSH G. SIP H. SSL I. SFTP

Computer Science & Information Technology