beyondgrader.com Logo
DemoBrowseAboutTeamLogin

Insertion Sort (int)

Geoffrey Challen // 2021.4.0

Create a method sort that accepts non-null IntArray and sorts them in ascending order. You should sort the array in place, meaning that you modify the original array, and return the number of swaps required to sort the array as an int. That's how we'll know that you've correctly implemented insertion sort.

To receive credit implement insertion sort as follows. Have the sorted part start at the left and grow to the right. Each step takes the left-most value from the unsorted part of the array and move it leftward, swapping elements until it is in the correct place. Do not swap equal values. This will make your sort unstable and cause you to fail the test suites.