sicp-ex-2.24



<< Previous exercise (2.23) | Index | Next exercise (2.25) >>


Tree:

 (1 (2 (3 4)))
      ^
    /   \
   1     ^ (2 (3 4))
       /   \
      2     ^ (3 4)
          /   \
         3     4

jz

  (list 1 (list 2 (list 3 4)))

Printed result: (1 (2 (3 4)))

Box and pointer:

                 
 (1 (2 (3 4)))  ((2 (3 4)))                                              
   +---+---+    +---+---+
   | * | *-+--->| * | / |
   +-+-+---+    +-+-+---+
     |            |   
     V            V (2 (3 4))   ((3 4))   
   +---+        +---+---+      +---+---+
   | 1 |        | * | *-+----->| * | / | 
   +---+        +-+-+---+      +---+---+
                  |              |
                  V              V (3 4)
                +---+          +---+---+    +---+---+
                | 2 |          | * | *-+--->| * | / |
                +---+          +-+-+---+    +-+-+---+
                                 |            |
                                 V            V
                               +---+        +---+
                               | 3 |        | 4 |
                               +---+        +---+