{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Lecture 5

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

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

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.

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

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

{[ snackBarMessage ]}