Optimal insert for a sorted array implemented