forked from cedille/ial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvector-sort.agda
More file actions
23 lines (19 loc) Β· 957 Bytes
/
vector-sort.agda
File metadata and controls
23 lines (19 loc) Β· 957 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
module vector-sort where
open import level
open import bool
open import nat
open import product
open import vector
insertπ : β{β}{A : Set β}{n : β} β (_<_ : A β A β πΉ) β (_β
_ : A β A β πΉ) β A β π A n β Ξ£i β (Ξ» m β π A (suc m))
insertπ _<_ _β
_ x [] = , [ x ]π
insertπ _<_ _β
_ x (y :: ys) with x < y
... | tt = , x :: y :: ys
... | ff with x β
y
... | tt = , y :: ys
... | ff with (insertπ _<_ _β
_ x ys)
... | , r = , y :: r
insertion-sortπ : β{β}{A : Set β}{n : β} β (_<_ : A β A β πΉ) β (_β
_ : A β A β πΉ) β π A (suc n) β Ξ£i β (Ξ» m β π A (suc m))
insertion-sortπ _ _ (x :: []) = , [ x ]π
insertion-sortπ _<_ _β
_ (x :: (y :: ys)) with insertion-sortπ _<_ _β
_ (y :: ys)
... | , (z :: zs) = insertπ _<_ _β
_ x (z :: zs)
test-insertion-sortπ = insertion-sortπ _<_ _=β_ (3 :: 5 :: 2 :: 7 :: 1 :: 2 :: 3 :: 9 :: [])