Darren There's an error in your insertion sort code a(j) := a(j) which is probably not what you intended to write.