mirror of
https://github.com/idris-lang/Idris2.git
synced 2024-12-15 06:13:26 +03:00
4f10bfcfd2
This is referred to in the documentation, so should be there
22 lines
516 B
Idris
22 lines
516 B
Idris
module BTree
|
|
|
|
public export
|
|
data BTree a = Leaf
|
|
| Node (BTree a) a (BTree a)
|
|
|
|
export
|
|
insert : Ord a => a -> BTree a -> BTree a
|
|
insert x Leaf = Node Leaf x Leaf
|
|
insert x (Node l v r) = if (x < v) then (Node (insert x l) v r)
|
|
else (Node l v (insert x r))
|
|
|
|
export
|
|
toList : BTree a -> List a
|
|
toList Leaf = []
|
|
toList (Node l v r) = BTree.toList l ++ (v :: BTree.toList r)
|
|
|
|
export
|
|
toTree : Ord a => List a -> BTree a
|
|
toTree [] = Leaf
|
|
toTree (x :: xs) = insert x (toTree xs)
|