DOC PREVIEW
MIT 6 001 - Stacks and Queues

This preview shows page 1-2-3-4 out of 13 pages.

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

Unformatted text preview:

6.001 recitation 3/16/07tagsstacks and queuesDr. Kimberle Koile(car ‘ ‘list)tagsstacks and queues• constructor: (make-stack) • selectors: (top stack) (stack-elements stack)• operations: (stack? stack)(empty-stack? stack)(insert-stack-elt stack elt) (delete-stack-elt stack) stacks• constructor: (define (make-stack) • selectors: (define (top stack)• operations: (define (stack? stack)(define (empty-stack? stack)stacks(define (tagged-list? tag l) (and (pair? l) (eq? tag (car l))))(define *stack-tag* 'stack)1. Fill in the code for insert-stack-elt (aka push) for a stack.(define (insert-stack-elt element stack)(if (stack? stack)(cons(error "Insert on a non-stack")))stack problems(cons)2. Write delete-stack-elt (aka pop) for a stack. This version of pop should return a new stack that contains all elements except the top. (Don't forget the two error checks.)stack problems(define delete-stack-elt (stack))• constructor: (make-queue) • selectors: (front-queue queue) (queue-elements queue)• operations: (queue? queue)(empty-queue? queue)(insert-queue-elt queu elt) (delete-queue-elt queue) queues(define (tagged-list? tag l) (and (pair? l) (eq? tag (car l))))(define *queue-tag* 'queue)3. Write insert-queue-elt for a queue. (Don't forget an error check.)queue problems(define insert-queue-elt (queue))4. Write delete-queue-elt for a queue. (Don't forget an error check.)queue problems(define delete-queue-elt (queue))• constructor: (make-it) • selectors: (first-elt s-or-q) (elements s-or-q)• operations: (is-type? s-or-q)(empty? s-or-q)(insert-element s-or-q elt) (delete-element s-or-q) stacks and queues(define delete-elt s-or-q))5.Write a delete-elt procedure that works on either stacks or queues.stacks and queuesacdstacksX(delete! s)stacks and


View Full Document

MIT 6 001 - Stacks and Queues

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 Stacks and Queues
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 Stacks and Queues 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 Stacks and Queues 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?