Last active
December 13, 2017 08:41
-
-
Save dheshanm/b09dbab78a61c560cc290ed95b133bb0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
procedure insertionSort( A : array of items ) | |
int holePosition | |
int valueToInsert | |
for i = 1 to length(A) inclusive do: | |
/* select value to be inserted */ | |
valueToInsert = A[i] | |
holePosition = i | |
/*locate hole position for the element to be inserted */ | |
while holePosition > 0 and A[holePosition-1] > valueToInsert do: | |
A[holePosition] = A[holePosition-1] | |
holePosition = holePosition -1 | |
end while | |
/* insert the number at hole position */ | |
A[holePosition] = valueToInsert | |
end for | |
end procedure |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment