Skip to content

Instantly share code, notes, and snippets.

@vaidehijoshi
Last active May 29, 2017 06:10
Show Gist options
  • Save vaidehijoshi/f70a3e53b36f8f15d851baaa7482e97a to your computer and use it in GitHub Desktop.
Save vaidehijoshi/f70a3e53b36f8f15d851baaa7482e97a to your computer and use it in GitHub Desktop.
Insertion sort results
> var a = [4, -31, 0, 99, 83, 1];
> insertionSort(a);
> currentUnsortedItem is currently 4
> ** inserting 4 at index 0
> array is now: 4,-31,0,99,83,1
> currentUnsortedItem is currently -31
> -31 < 4 is true
> ** inserting 4 at index 1
> ** inserting -31 at index 0
> array is now: -31,4,0,99,83,1
> currentUnsortedItem is currently 0
> 0 < 4 is true
> ** inserting 4 at index 2
> ** inserting 0 at index 1
> array is now: -31,0,4,99,83,1
> currentUnsortedItem is currently 99
> ** inserting 99 at index 3
> array is now: -31,0,4,99,83,1
> currentUnsortedItem is currently 83
> 83 < 99 is true
> ** inserting 99 at index 4
> ** inserting 83 at index 3
> array is now: -31,0,4,83,99,1
> currentUnsortedItem is currently 1
> 1 < 99 is true
> ** inserting 99 at index 5
> 1 < 83 is true
> ** inserting 83 at index 4
> 1 < 4 is true
> ** inserting 4 at index 3
> ** inserting 1 at index 2
> array is now: -31,0,1,4,83,99
>> (6) [-31, 0, 1, 4, 83, 99]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment