CS116 Chapter Notes - Chapter 9: Flattening

27 views1 pages

Document Summary

;; (flatten l) produces a flat list from l. ;; flatten: llt->(listof num) (define (flatten l) (cond. [(cons? (first l)) (append (flatten (first l)) (flatten (rest l)))] Remember: use append only when the first list has length greater than one, or there are more than two lists. Defined a structure with three fields: the operation, the first argument, and the second argument. Consider nested lists (arbitrary nesting): (list (list 1 (list 2 3)) 4 (list 5 (list 6 7 8) 9)) Leaves correspond to the elements of the list, and the internal nodes indicate the nesting. Each non-empty tree is a list of sub trees: The first sub tree in the list is either. A single leaf (not a list) or. A sub tree rooted at an internal node (a list). ;; a leaf-labelled tree (llt) is one of the following. Template for leaf-labeled trees (define (my-llt-fun l) (cond. [else (first l) (my-llt-fun (rest l)) ]))

Get access

Grade+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers

Related Documents