This preview shows page 1 out of 4 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 4 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 4 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

6.001, Fall 2004—Quiz 2 Review 1MASSACHVSETTS INSTITVTE OF TECHNOLOGYDepartment of Electrical Engineering and Computer Science6.001—Structure and Interpretation of Computer ProgramsFall 2004Quiz 2 ReviewTutorialStacks(define (make-stack)(list ’stack ’()))(define (stack? x)(and (pair? x) (eq? (car x) ’stack)))1. Write stack-add:(define (stack-add elem stack)2. Write stack-next:(define (stack-next stack)3. Write stack-empty?:(define (stack-empty? stack)Queues(define (make-queue)(list ’queue ’()))(define (queue? x)(and (pair? x) (eq? (car x) ’queue)))6.001, Fall 2004—Quiz 2 Review 24. Write queue-add:(define (queue-add elem queue)5. Write queue-next:(define (queue-next queue)6. Write queue-empty?:(define (queue-empty? queue)IteratorsAbstraction on top of stacks and queues. Three methods: add, next, empty?. Should be able todrop in a stack or a queue and use them interchangably.(define (iadd elem it)(cond ((stack? it) (stack-add elem it))((queue? it) (queue-add elem it))(else (error "huh?"))))(define (inext it)(cond ((stack? it) (stack-next it))((queue? it) (queue-next it))(else (error "huh?"))))Problems?6.001, Fall 2004—Quiz 2 Review 3(define (make-iterator constructor add next empty?)(let ((val (constructor)))(list ’iterator(lambda (elem)(add elem val))(lambda ()(next val))(lambda ()(empty? val)))))7. Write iadd:(define (iadd elem it)8. Write inext:(define (inext it)9. Write iempty?:(define (iempty? it)10. Environment model?6.001, Fall 2004—Quiz 2 Review 411. Add a counter that counts the number of operations done on the iterator. Also add an extraprocedure that returns the value of the c


View Full Document

MIT 6 001 - Quiz 2 Review

Documents in this Course
Quiz 1

Quiz 1

6 pages

Databases

Databases

12 pages

rec20

rec20

2 pages

Quiz II

Quiz II

15 pages

Streams

Streams

5 pages

Load more
Download Quiz 2 Review
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Quiz 2 Review and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Quiz 2 Review 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?