Implements insertion sort.