Another update from ingydotnet^djgoku
This commit is contained in:
parent
91df62d461
commit
948b86eafa
7604 changed files with 108452 additions and 22726 deletions
32
Task/Visualize-a-tree/Common-Lisp/visualize-a-tree-1.lisp
Normal file
32
Task/Visualize-a-tree/Common-Lisp/visualize-a-tree-1.lisp
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
(defun visualize (tree)
|
||||
(labels
|
||||
((rprint (list)
|
||||
(mapc #'princ (reverse list)))
|
||||
(vis-h (tree branches)
|
||||
(let ((len (length tree)))
|
||||
(loop
|
||||
for item in tree
|
||||
for idx from 1 to len do
|
||||
(cond
|
||||
((listp item)
|
||||
(rprint (cdr branches))
|
||||
(princ "+---+")
|
||||
(let ((next (cons "| "
|
||||
(if (= idx len)
|
||||
(cons " " (cdr branches))
|
||||
branches))))
|
||||
(terpri)
|
||||
(rprint (if (null item)
|
||||
(cdr next)
|
||||
next))
|
||||
(terpri)
|
||||
(vis-h item next)))
|
||||
(t
|
||||
(rprint (cdr branches))
|
||||
(princ item)
|
||||
(terpri)
|
||||
(rprint (if (= idx len)
|
||||
(cdr branches)
|
||||
branches))
|
||||
(terpri)))))))
|
||||
(vis-h tree '("| "))))
|
||||
32
Task/Visualize-a-tree/Common-Lisp/visualize-a-tree-2.lisp
Normal file
32
Task/Visualize-a-tree/Common-Lisp/visualize-a-tree-2.lisp
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
CL-USER> (visualize '(a b c ((d (e ((() ()))) f)) (g)))
|
||||
A
|
||||
|
|
||||
B
|
||||
|
|
||||
C
|
||||
|
|
||||
+---+
|
||||
| |
|
||||
| +---+
|
||||
| |
|
||||
| D
|
||||
| |
|
||||
| +---+
|
||||
| | |
|
||||
| | E
|
||||
| | |
|
||||
| | +---+
|
||||
| | |
|
||||
| | +---+
|
||||
| | |
|
||||
| | +---+
|
||||
| | |
|
||||
| | +---+
|
||||
| |
|
||||
| F
|
||||
|
|
||||
+---+
|
||||
|
|
||||
G
|
||||
|
||||
NIL
|
||||
Loading…
Add table
Add a link
Reference in a new issue