CS112_48_StanfordFinalSolns

# CS112_48_StanfordFinalSolns - Handout#52S CS106B Practice...

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

Handout #52S Spring 2002 May 22, 2002 Robert Plummer Practice Final Solutions Problem 1: Recursion (25 points) bool CanBeSeated(string guests[]) { int i; string table[NUM_GUESTS]; for (i = 0; i < NUM_GUESTS; i++) table[i] = ""; return CanBeSeatedRec(guests, table, 1); } // On every call try to seat a guest somewhere and call recursively. // Try all possible seats and return FALSE if all choices failed. bool CanBeSeatedRec(string guests[], string table[], int nextGuest) { int i; if (nextGuest == NUM_GUESTS) { return TRUE; } // Find an empty seat and see if the next person fits for (i = 0; i < NUM_GUESTS; i++) { if ((StringLength(table[i]) == 0) && AreFriends(table[(i + 1) % NUM_GUESTS], guests[nextGuest]) && AreFriends(table[(i + NUM_GUESTS - 1) % NUM_GUESTS], guests[nextGuest])) { table[i] = guests[nextGuest]; if (CanBeSeatedRec(guests, table, nextGuest + 1)) return TRUE; table[i] = ""; } } return FALSE; } CS106B

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

View Full Document
2 Problem 2: Function Pointers, Mapping, Iteration (25 points) int WidgetBattle(
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 4

CS112_48_StanfordFinalSolns - Handout#52S CS106B Practice...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online