sicp-ex-3.21



<< Previous exercise (3.21) | Index | Next exercise (3.22) >>


meteorgan

  
  
 (define (print-queue queue) (car queue)) 

Shawn

The exercise asks us to print the queue, not return the queue. Also, we should use procedures like front-ptr instead of car. Here is my solution:

 (define (print-queue q) 
   (define (iter x) 
     (if (null? x) 
         (newline) 
         (begin (display (car x)) 
                (iter (cdr x))))) 
   (iter (front-ptr q)))