Skip to content

Commit

Permalink
Merge pull request #970 from haashem/master
Browse files Browse the repository at this point in the history
Update `InsertionSort` README.markdown
  • Loading branch information
richard-ash authored May 11, 2021
2 parents 2fdd8b8 + d664df8 commit 5d55104
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion Insertion Sort/README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ insertionSort(list)

Here is how the code works.

1. Make a copy of the array. This is necessary because we cannot modify the contents of the `array` parameter directly. Like Swift's own `sort()`, the `insertionSort()` function will return a sorted *copy* of the original array.
1. Make a copy of the array. This is necessary because we cannot modify the contents of the `array` parameter directly. Like Swift's own `sorted()`, the `insertionSort()` function will return a sorted *copy* of the original array.

2. There are two loops inside this function. The outer loop looks at each of the elements in the array in turn; this is what picks the top-most number from the pile. The variable `x` is the index of where the sorted portion ends and the pile begins (the position of the `|` bar). Remember, at any given moment the beginning of the array -- from index 0 up to `x` -- is always sorted. The rest, from index `x` until the last element, is the unsorted pile.

Expand Down

0 comments on commit 5d55104

Please sign in to comment.