CS112_48_StanfordFinalSolns

CS112_48_StanfordFinalSolns - Handout #52S May 22, 2002...

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

View Full Document Right Arrow Icon
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
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 Problem 2: Function Pointers, Mapping, Iteration (25 points) int WidgetBattle(
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 4

CS112_48_StanfordFinalSolns - Handout #52S May 22, 2002...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online