Pouknouki

Caml ?

May 11th, 2016
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
OCaml 2.31 KB | None | 0 0
  1. (*let insertion vec = function
  2.     for i = 0 to vect_length(vec) do
  3.         let j = ref 1 in
  4.         let val = vec.(i) in
  5.         while vec.(i-j) > val do
  6.             vec.(i-j+1) <-vec.(i-j)
  7.             j := !j + 1
  8.         done;
  9.         vec.(i-j) <- val;
  10.     done;
  11.     for i = 0 to vect_length(vec) do
  12.         print_int(vec.(i))
  13.     end;;
  14.  
  15. let vect = make_vect 5 5 in
  16. vect.(1) <- 3
  17. vect.(2) <- 1
  18. insertion vect;;*)
  19.  
  20. let rec insererliste liste valeur = match liste with
  21.     | [] -> [valeur]
  22.     | t::q -> if t <= valeur then valeur::(t::q) else t::(insererliste q valeur);;
  23.  
  24. let rec insertion liste = match liste with
  25.     | [] -> []
  26.     | [t] -> [t]
  27.     | t::q -> insererliste (insertion q) t;;
  28.  
  29. let rec print_list = function
  30. [] -> ()
  31. | e::l -> print_int e ; print_string " " ; print_list l;;
  32.  
  33.  
  34.  
  35. let rec minAux l = match l with
  36.     | [] -> failwith "En fait non.."
  37.     | [t] -> t
  38.     | t::q -> if t < min q then t else min q;;
  39.  
  40. let rec minPrive l v = match l with
  41.     | [] -> []
  42.     | [t] -> if t == v then [] else [t]
  43.     | t::q -> if t == v then q else t::(minPrive q v);;
  44.  
  45. (*let insertion vec = function
  46.     for i = 0 to vect_length(vec) do
  47.         let j = ref 1 in
  48.         let val = vec.(i) in
  49.         while vec.(i-j) > val do
  50.             vec.(i-j+1) <-vec.(i-j)
  51.             j := !j + 1
  52.         done;
  53.         vec.(i-j) <- val;
  54.     done;
  55.     for i = 0 to vect_length(vec) do
  56.         print_int(vec.(i))
  57.     end;;
  58.  
  59. let vect = make_vect 5 5 in
  60. vect.(1) <- 3
  61. vect.(2) <- 1
  62. insertion vect;;*)
  63.  
  64. let rec insererliste liste valeur = match liste with
  65.     | [] -> [valeur]
  66.     | t::q -> if t <= valeur then valeur::(t::q) else t::(insererliste q valeur);;
  67.  
  68. let rec insertion liste = match liste with
  69.     | [] -> []
  70.     | [t] -> [t]
  71.     | t::q -> insererliste (insertion q) t;;
  72.  
  73. let rec print_list = function
  74. [] -> ()
  75. | e::l -> print_int e ; print_string " " ; print_list l;;
  76.  
  77.  
  78.  
  79. let rec minAux l = match l with
  80.     | [] -> failwith "En fait non.."
  81.     | [t] -> t
  82.     | t::q -> if t < min q then t else min q;;
  83.  
  84. let rec minPrive l v = match l with
  85.     | [] -> []
  86.     | [t] -> if t == v then [] else [t]
  87.     | t::q -> if t == v then q else t::(minPrive q v);;
  88.  
  89. let rec selection l = match l with
  90.     | [] -> []
  91.     | l -> (min l)::(selection (minPrive l (min l)));;
  92.  
  93. print_list (selection [3;4;2;1]);;
  94.  
  95. let rec passe l = match l with
  96.     | [] -> []
  97.     | [h] -> [h]
  98.     | t1::t2::q -> if t2 > t1 then t2::(t1::(passe q)) else t1::(t2::(passe q));;
  99.  
  100. print_list (passe [3;4;1;2]);;
Advertisement
Add Comment
Please, Sign In to add comment