epicours/Exam.md

315 B

Multiple insertion

let insert_mult n x lst =
	if n <= 0 then
		invalid_arg "insert_mult: n must be > 0"
	else
		match lst with
			| [] -> []
			| z::f -> 
				let aux count = function
					| [] -> x
					| e::t -> 
						if (count = n) then
							e :: x :: t
						else aux (count + 1) t
				in aux 1 t