Insertion sort in an array

I have created a help function (insertinorder) inorder for the function insertionsort to go through all of the elements, but I can’t still get the functions working correct.

Can someone assist me in what I am doing wrong?

     let rec insertinorder(array,end) =
        let temp = array.(end) in
        if array.(end-1) > temp
        then array.(end) = array.(end-1)
        array.(end-1) = temp
        if end > 1
        then insertinorder(array,end-1)
        else ();;

    let rec insertionsort (array, current) =
    if current > array.length-1
    then ()
    else insertinorder(array, current)
    insertionsort(array, current +1);;

As a zeroth step, you should try to make your code compile (end is a keyword).

What is zeroth step?

How would it be compiled?

It is the minimal step that you should have taken before asking your question.

How are you even working? Are you writing code on paper in pseudo-code? Anyway, write your code in the REPL or compile it with ocamlc or ocamlopt and get rid of your parser and type errors, then update your question.

Hint: you should also use -strict-sequence.

1 Like

Nevermind, I solved it.