Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 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
|
||||
16
Task/Visualize-a-tree/Common-Lisp/visualize-a-tree-3.lisp
Normal file
16
Task/Visualize-a-tree/Common-Lisp/visualize-a-tree-3.lisp
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
(use-package :iterate)
|
||||
(defun print-tree (tree value-function children-function)
|
||||
(labels
|
||||
((do-print-tree (tree prefix)
|
||||
(format t "~a~%" (funcall value-function tree))
|
||||
(iter
|
||||
(with children = (funcall children-function tree))
|
||||
(for child = (pop children))
|
||||
(while child)
|
||||
|
||||
(if children
|
||||
(progn (format t "~a├─ " prefix)
|
||||
(do-print-tree child (format nil "~a│ " prefix)))
|
||||
(progn (format t "~a└─ " prefix)
|
||||
(do-print-tree child (format nil "~a " prefix)))))))
|
||||
(do-print-tree tree "")))
|
||||
27
Task/Visualize-a-tree/Common-Lisp/visualize-a-tree-4.lisp
Normal file
27
Task/Visualize-a-tree/Common-Lisp/visualize-a-tree-4.lisp
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
CL-USER>(print-tree '(a
|
||||
(aa
|
||||
(aaa
|
||||
(aaaa)
|
||||
(aaab
|
||||
(aaaba)
|
||||
(aaabb))
|
||||
(aaac)))
|
||||
(ab)
|
||||
(ac
|
||||
(aca)
|
||||
(acb)
|
||||
(acc)))
|
||||
#'car #'cdr)
|
||||
A
|
||||
├─ AA
|
||||
│ └─ AAA
|
||||
│ ├─ AAAA
|
||||
│ ├─ AAAB
|
||||
│ │ ├─ AAABA
|
||||
│ │ └─ AAABB
|
||||
│ └─ AAAC
|
||||
├─ AB
|
||||
└─ AC
|
||||
├─ ACA
|
||||
├─ ACB
|
||||
└─ ACC
|
||||
Loading…
Add table
Add a link
Reference in a new issue