CS 119 Lab 9 – Mutable data structures
Objectives
1.Open the file lab9.scm and look at the function mystery. Without running the function, see if you can figure out what will happen with the following by drawing the box and pointer pictures.
Þ
(define v ‘(a b c d))
Þ
(mystery v)
Þ
v
Try the commands above and see if you were right. If you are still confused, try putting in (display x) (display y) (display temp) (newline) immediately after the let.
2.Evaluate the functions for implementing a queue in lab9.scm. Try creating a queue and inserting the values ‘a and ‘b :
Þ
(define q1 (make-queue))
Þ
(insert-queue! q1 ‘a)
Þ
(insert-queue! q1 ‘b)
Why did you get the strange output on the insert-queue! commands?
Before trying each of the following commands, consider what output you expect.
Þ
(front q1)
Þ
(delete-queue! q1)
Þ
(front q1)
Þ
(delete-queue! q1)
Þ
(front q1)
3. Open the file deque.scm. This file contains the incomplete code for implementing a double-ended queue. A double-ended queue may have values inserted or deleted at either the front or the rear. In order for all of these commands to be performed in O(1) time, we are implementing the deque as a doubly linked list. Why will a regular list be inadequate?
A constructor (make-node item) is provided for creating a node in the list which contains the item in the node, as well as a previous and next pointer. Selectors are provided for accessing the previous and next pointers, as well as mutators which will modify these values. If we maintain abstraction barriers, then this is all we need to write the code for implementing the deque.
|
Assignment: Note: We can not print out the value of the deque directly because of the circular nature of the doubly linked list. If this inadvertently happens, you may terminate the evaluation by using the F4 key. |
4. Email your files containing the assignment to jzimmerm@goucher.edu.