This book is now obsolete Please use CSAwesome instead.

13.5. Insertion SortΒΆ

The insertion sort that you need to know for the exam starts at index 1 and inserts the value at index 1 into its correct place in the already sorted part (the part to the left of the current index). It moves any value larger than the value stored in temp to the right until it either finds the appropriate place to put temp or gets to the front of the array.

To identify an insertion sort look for the following:

The code for insertionSort below is from the AP CS A course description.

To see this executing using the Java Visualizer click on the following Insertion-Sort

You can step through the code above by clicking on the following Ex-12-5-2.

You have attempted of activities on this page