{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

lispwu

# lispwu - LISP Warmup Fall 2011 CMSC 420 Hanan Samet This...

This preview shows pages 1–2. Sign up to view the full content.

Fall 2011 LISP Warmup CMSC 420 Hanan Samet This problem reflects the philosophy that one learns fastest and best by doing. In this problem, you will be asked to run a given LISP program and observe and describe its behavior. For this exercise, we will need two LISP data structures, tree1 (a binary tree), and tree2 (a general tree): B D C E A F G H I Figure 1: tree1 A C F D L J O N K P M H I E B G Figure 2: tree2 We will represent these two trees in LISP parenthesized notation. To begin this exercise type lisp into the command shell. At this point, you will be talking to LISP. Next, set up this exercise by typing the following five s-expressions: Define tree1 : (setq tree1 ’(a (b (c nil nil) nil) (d (e nil nil) (f (g (h nil nil) (i nil nil)) nil))) ) Define tree2 : (setq tree2 ’(a (b (f) (g)) (c (h (i))) (d (j) (k) (l)) (e (m (n (p))(o)))) ) Define function searchb : (defun searchb (tree node) (cond ((null tree) nil) (t (or (eq (car tree) node) (searchb (cadr tree) node) (searchb (caddr tree) node))))) Define function searcht : (defun searcht (tree node) (cond ((null tree) nil)

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}