-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Joseph Williamson
committed
Jun 7, 2019
1 parent
b549fe9
commit 2b1d683
Showing
1 changed file
with
23 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#lang sicp | ||
(define (make-tree entry left right) (cons entry (cons left right))) | ||
(define (left-branch tree) (cadr tree)) | ||
(define (right-branch tree) (cddr tree)) | ||
(define (entry-tree tree) (car tree)) | ||
(define lefts-left (make-tree 'c '() '())) | ||
(define rights-left (make-tree 'q '() '())) | ||
(define l1 (make-tree 'f lefts-left '())) | ||
(define r1 (make-tree 'z rights-left '())) | ||
(define t1 (make-tree 'm l1 r1)) | ||
|
||
(left-branch t1) | ||
(right-branch t1) | ||
|
||
t1 | ||
|
||
(define (invert-tree tree) | ||
(cond ((null? tree) '()) | ||
((cons (entry-tree tree) | ||
(cons (invert-tree (right-branch tree)) | ||
(invert-tree (left-branch tree))))))) | ||
|
||
(invert-tree t1) |