td5
This commit is contained in:
parent
7ecbf70590
commit
f24f834ae0
26
td5/dune-project
Normal file
26
td5/dune-project
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
(lang dune 3.20)
|
||||||
|
|
||||||
|
(name td5)
|
||||||
|
|
||||||
|
(generate_opam_files true)
|
||||||
|
|
||||||
|
(source
|
||||||
|
(github username/reponame))
|
||||||
|
|
||||||
|
(authors "Author Name <author@example.com>")
|
||||||
|
|
||||||
|
(maintainers "Maintainer Name <maintainer@example.com>")
|
||||||
|
|
||||||
|
(license LICENSE)
|
||||||
|
|
||||||
|
(documentation https://url/to/documentation)
|
||||||
|
|
||||||
|
(package
|
||||||
|
(name td5)
|
||||||
|
(synopsis "A short synopsis")
|
||||||
|
(description "A longer description")
|
||||||
|
(depends ocaml)
|
||||||
|
(tags
|
||||||
|
("add topics" "to describe" your project)))
|
||||||
|
|
||||||
|
; See the complete stanza docs at https://dune.readthedocs.io/en/stable/reference/dune-project/index.html
|
||||||
10
td5/exo1.c
Normal file
10
td5/exo1.c
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#include "stdio.h"
|
||||||
|
#include "stdlib.h"
|
||||||
|
|
||||||
|
void intertion_sort(int t[], int n) {
|
||||||
|
for (int i = 1; i < n; i++) {
|
||||||
|
int j = 0;
|
||||||
|
while (j < i && t[j] <= t[i])
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
}
|
||||||
3
td5/lib/dune
Normal file
3
td5/lib/dune
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
(library
|
||||||
|
(name lib)
|
||||||
|
(public_name td5))
|
||||||
29
td5/lib/lib.ml
Normal file
29
td5/lib/lib.ml
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
(* Exercice 1 *)
|
||||||
|
(* Insertion sort *)
|
||||||
|
let rec insert l x = match l with
|
||||||
|
| [] -> [x]
|
||||||
|
| y::t -> if x <= y then x::l else y::(insert t x)
|
||||||
|
;;
|
||||||
|
|
||||||
|
let insertion_sort l =
|
||||||
|
List.fold_left
|
||||||
|
(fun acc x -> insert acc x)
|
||||||
|
[]
|
||||||
|
l
|
||||||
|
;;
|
||||||
|
|
||||||
|
(* Selection sort *)
|
||||||
|
let rec min_l l = match l with
|
||||||
|
| [] -> invalid_arg "Empty list"
|
||||||
|
| [x] -> x, []
|
||||||
|
| x::q ->
|
||||||
|
let y, qy = min_l q in
|
||||||
|
if x < y then x, q else y, (x::qy)
|
||||||
|
;;
|
||||||
|
|
||||||
|
let rec selection_sort l = match l with
|
||||||
|
| [] | _::[] -> l
|
||||||
|
| _ ->
|
||||||
|
let m, q = min_l l in
|
||||||
|
m::(selection_sort q)
|
||||||
|
;;
|
||||||
32
td5/td5.opam
Normal file
32
td5/td5.opam
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
# This file is generated by dune, edit dune-project instead
|
||||||
|
opam-version: "2.0"
|
||||||
|
synopsis: "A short synopsis"
|
||||||
|
description: "A longer description"
|
||||||
|
maintainer: ["Maintainer Name <maintainer@example.com>"]
|
||||||
|
authors: ["Author Name <author@example.com>"]
|
||||||
|
license: "LICENSE"
|
||||||
|
tags: ["add topics" "to describe" "your" "project"]
|
||||||
|
homepage: "https://github.com/username/reponame"
|
||||||
|
doc: "https://url/to/documentation"
|
||||||
|
bug-reports: "https://github.com/username/reponame/issues"
|
||||||
|
depends: [
|
||||||
|
"dune" {>= "3.20"}
|
||||||
|
"ocaml"
|
||||||
|
"odoc" {with-doc}
|
||||||
|
]
|
||||||
|
build: [
|
||||||
|
["dune" "subst"] {dev}
|
||||||
|
[
|
||||||
|
"dune"
|
||||||
|
"build"
|
||||||
|
"-p"
|
||||||
|
name
|
||||||
|
"-j"
|
||||||
|
jobs
|
||||||
|
"@install"
|
||||||
|
"@runtest" {with-test}
|
||||||
|
"@doc" {with-doc}
|
||||||
|
]
|
||||||
|
]
|
||||||
|
dev-repo: "git+https://github.com/username/reponame.git"
|
||||||
|
x-maintenance-intent: ["(latest)"]
|
||||||
4
td5/test/dune
Normal file
4
td5/test/dune
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
(executable
|
||||||
|
(name test)
|
||||||
|
(public_name test)
|
||||||
|
(libraries lib))
|
||||||
7
td5/test/test.ml
Normal file
7
td5/test/test.ml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
open Lib;;
|
||||||
|
|
||||||
|
let l = [5; 3; 9; 0; 5; 0];;
|
||||||
|
let sorted = [0; 0; 3; 5; 5; 9];;
|
||||||
|
|
||||||
|
assert (insertion_sort l = sorted);;
|
||||||
|
assert (selection_sort l = sorted);;
|
||||||
Loading…
Reference in New Issue
Block a user