{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Lecture 5 - Another solution to the writeback problem void...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
1 Another solution to the writeback problem: void writeback(char S[], int size, int pos) { if (pos < size) { writeback(S, size, pos+1); cout << S[pos]; } { 2 We need to call this as follows: Assume again that ST contains the characters C A T writeback(ST, 3, 0); Note that this procedure does SOMETHING after the recursive call. This is harder. 3 Inside of writeback(ST, 3, 0) nothing happens before the recursive call. The recursive call will be: writeback(S, 3, 1) 4 Inside of writeback(S, 3, 1) nothing happens before the recursive call. The recursive call will be writeback(S, 3, 2). Inside of writeback(S, 3, 2) nothing happens before the recursive call. The recursive call will be writeback(S, 3, 3). 5 writeback( ) Return Path writeback(S, 3, 3) will not do anything, because the IF condition evaluates to FALSE. writeback(S, 3, 3) returns to writeback(S, 3, 2). writeback(S, 3, 2) sends T to the screen. writeback(S, 3, 2) returns to writeback(S, 3, 1). writeback(S, 3, 1) sends A to the screen.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

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

{[ snackBarMessage ]}