Sorting algorithms/Tree sort on a linked list: Difference between revisions
Content added Content deleted
(Added Go) |
(added Ol) |
||
Line 238: | Line 238: | ||
5 3 7 9 1 -> 1 3 5 7 9 |
5 3 7 9 1 -> 1 3 5 7 9 |
||
d c e b a -> a b c d e |
d c e b a -> a b c d e |
||
</pre> |
|||
=={{header|Ol}}== |
|||
Ol has builtin sorted key-value trees named "ff". We converting list into ff and back again as already sorted list. Only values (small integers, constants) and symbols are allowed. |
|||
<lang scheme> |
|||
(define (tree-sort l) |
|||
(map car (ff->list |
|||
(fold (lambda (ff p) |
|||
(put ff p #t)) |
|||
#empty l)))) |
|||
(print (tree-sort '(5 3 7 9 1))) |
|||
</lang> |
|||
{{out}} |
|||
<pre> |
|||
(1 3 5 7 9) |
|||
</pre> |
</pre> |
||