Lecture 4

15 void writebackwardchar s int size if size 0

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: g the array that is left backwards. If we come down to an array of size 0, we do nothing. 15 void writebackward(char S, int size) { if (size > 0) { cout << S[size-1]; writebackward(S, size-1); } } 17 16 Let’ trace through this with the following s example: Assume that ST contains the characters C A T. writebackward(ST, 3) is now called. Within writebackward( ) we have therefore: S CA T size 18 3 cout << S[3-1]; will send to the screen: T Then comes the recursive call to writebackward(S,2) Note that S is never changed in the process. 19 writebackward(S,1) will first do cout << S[1-1]; which will write to screen: C Then comes the recursive call to writebackward(S,0) writebackward(S,2) will first do cout << S[2-1]; which will write to screen: A Then comes the recursive call to writeba...
View Full Document

Ask a homework question - tutors are online