CISC-280 Program Development Techniques

Homework 3: Data Abstraction, Lists, and Trees

Due: Friday, March 12, 2004

1. (8 points) Exercise 2.2, page 89, constructor and selectors for representing line segments in a plane.

2. (6 points) Exercise 2.4, page 92, procedural representation for pairs.


Fun With Lists

3. (10 points) Exercise 2.18, page 103, reversing a list.. Extra credit: solve this both as an iterative process and as a recursive process.

4. (12 points) Read exercise 2.20, page 104, and use those ideas to write a function called not-equal-first.  not-equal-first takes 1 or more integers and returns a list containing all of the original integers that are not equal to the first one.  E.g., (not-equal-first 1 2 1 3 1 4 1 5) returns (2 3 4 5). You may find the function eq? helpful. This function takes two expressions and returns #t if they are the same -- i.e., if they are the same symbol or made up of the same list cells.

5. (12 points) Write a function called palindromep that is given a list and returns #t if the list has the same sequence of elements when read left to right as when read right to left. It should return #f otherwise. Hint: Maybe the answer to 4 would help?


6. (10 points) Exercise 2.23, page 107, for-each.

7. (15 points) Exercise 2.27, page 110, deep reverse. Extra credit: in addition to the standard implementation, do an implementation that uses map (and the reverse procedure from above).

8. (12 points) Exercise 2.28, page 111, fringe.

9. (15 points) Exercise 2.30, page 112, square-tree.