Computer Science 61A - Spring 2006 - Harvey - Midterm 3 Solutions

# Computer Science 61A - Spring 2006 - Harvey - Midterm 3 Solutions

• Notes
• 10

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

1 of 10 5/11/2006 12:10 AM CS 61A Spring 2006 Midterm 3 solutions 1. Box and pointer. > (let ((x (list 1 2 3))) (set-car! (cdr x) (cddr x)) x) (1 (3) 3) +-------------+ | | | V --------- --|------ --------- | | | | | | | | | /| ---->| | ------>| | ------>| | / | | | | | | : | | | | |/ | --|------ --:------ --|------ | : | V V V 1 2 3 (Some people had correct diagrams but wanted to print (1 3) or (1 3 3). The backbone of this list still has three pairs, so the list still has three elements! And the car of the second pair is a pair, not the number 3.) > (let ((x (list 1 2 3 4))) (set-car! (cddr x) (cons (cadr x) (cdddr x))) x) (1 2 (2 4) 4) ********* * | * 2 <-------- | -----------+ * | * | ********* | ^ | ! | ! V +---+---+ +---+---+ +-!-+---+ +---+---+ | | | | | | | ! | | | | /| x -------> | | | ----->| | | ----->| ! | ----->| | | / | | | | | | | | | | . | | | | |/ | +-|-+---+ +-|-+---+ +-.-+---+ +-|-+---+ | | . | | | . | V V V V 1 2 3 4 [In this problem a new pair is created. In the diagram above, the new pair is the one bordered by asterisks (*). That's because this problem invokes a constructor (CONS) rather than only mutators (SET-CxR!). The car of the new pair points to a number, whereas its cdr points to another pair. A very common error was to make an additional new pair with car 4 and cdr the empty list. But there's only one CONS in this problem, and it only makes one pair.] Scoring: One point for each diagram, one point for each print form. 2. Concurrency

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

This is the end of the preview. Sign up to access the rest of the document.
• Spring '08
• Harvey

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern