Anonymous user
Sorting algorithms/Insertion sort: Difference between revisions
m
better formatting of the pseudocode
(formatting) |
m (better formatting of the pseudocode) |
||
Line 3:
An [[O]](n<sup>2</sup>) sorting algorithm which moves elements one at a time into the correct position. The algorithm is as follows (from the [[wp:Insertion_sort#Algorithm|wikipedia]]):
'''function''' ''insertionSort''(array A)
'''for''' i
value := A[i]
j := i-1
'''while''' j >= 0 '''and''' A[j] > value '''do'''
A[j
j := j-1
'''done'''
A[j+1] = value
'''done'''
Writing the algorithm for integers will suffice.
|