Skip to content

Instantly share code, notes, and snippets.

@vaidehijoshi
Created July 17, 2017 01:30
Show Gist options
  • Save vaidehijoshi/434fbe31684468daf75b2b00570326a2 to your computer and use it in GitHub Desktop.
Save vaidehijoshi/434fbe31684468daf75b2b00570326a2 to your computer and use it in GitHub Desktop.
var array = [9,4,1,7,9,1,2,0]
countingSort(array, 0, 9)
> (10) [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
> (10) [1, 2, 1, 0, 1, 0, 0, 1, 0, 2]
> item at index 0 is: 9
> moving item 0 to correct location
> item at index 1 is: 4
> moving item 1 to correct location
> item at index 2 is: 1
> moving item 1 to correct location
> item at index 3 is: 7
> moving item 2 to correct location
> item at index 4 is: 9
> moving item 4 to correct location
> item at index 5 is: 1
> moving item 7 to correct location
> item at index 6 is: 2
> moving item 9 to correct location
> item at index 7 is: 0
> moving item 9 to correct location
> Hooray! Array is now sorted!
>> (8) [0, 1, 1, 2, 4, 7, 9, 9]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment