4 ms·
Not sure why, but I'd feel iffy iterating on a list while mutating its content. But I guess it's file while ignoring the order of the items, and just caring if
by seivan 11y ago
Not sure why, but I'd feel iffy iterating on a list while mutating its content.
But I guess it's file while ignoring the order of the items, and just caring if it's containing items or empty.
Carry on :)
- ICWiener 11y agoA functional approach: (defun mirror (tree) (when tree (tree (tree-data tree) (mirror (tree-right tree)) (mirror (tree-left tree))))) For completness, here are the definitions: (defpackage :trees (:use :cl) (:shadow #:copy-tree)) (in-package :trees) (defstruct (tree (:constructor tree (data &optional left right)) (:type list)) data left right) As well as a test case: (mirror (tree 4 (tree 2 (tree 1) (tree 3)) (tree 7 (tree 6) (tree 9)))) => (4 (7 (9 NIL NIL) (6 NIL NIL)) (2 (3 NIL NIL) (1 NIL NIL)))