Last active
December 16, 2015 19:49
-
-
Save thinkphp/5487441 to your computer and use it in GitHub Desktop.
Sorting a list using Binary Search Tree Traversal Inorder in Common Lisp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ; http://thinkphp.ro | |
| ; Adrian Statescu <mergesortv@gmail.com> | |
| ; | |
| ; Sorting a list using Binary Search Tree Traversal Inorder in Common Lisp | |
| ; | |
| ; License | |
| ; MIT | |
| ; | |
| ; 9 | |
| ; 3 | |
| ; 1 7 | |
| ; 8 | |
| ; | |
| ;L->(9 3 1 7 8) | |
| ; | |
| ;(inordine (arbore '(9 3 1 7 8) '<)) | |
| ; | |
| ;->(1 3 7 8 9) | |
| (defun arbore (L P) | |
| (labels (( arb (L TREE) | |
| (if (null L) TREE (arb (cdr L) (insereaza (car l) TREE P)) ) | |
| )) | |
| (arb L nil) | |
| ) | |
| ) | |
| (defun insereaza(A X P) | |
| (cond ((null X) (list A nil nil)) | |
| ((funcall p A (car X)) (list (car X) (insereaza A (cadr X) P) (caddr X) ) ) | |
| (T (list (car X) (cadr X) (insereaza A (caddr X) P) )) | |
| ) | |
| ) | |
| (defun inordine (TREE) | |
| (if (null TREE) nil (append (inordine (cadr TREE)) (list (car TREE) ) (inordine (caddr TREE)) ) ) | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment