| Introduction to Algorithms : A Sorting Algorithm | |||||||||
|
|||||||||
Algorithm Insertion_Sort (a[n]) |
|||||||||
| Step 1: | for i = 2 to n do | ||||||||
| Step 2: | current_num = a[i] | ||||||||
| Step 3: | |||||||||
j = i |
|||||||||
| Step 4: | while (( j >1) and (a[j-1] > current_num)) do |
||||||||
| Step 5: | |||||||||
a[j] = a[j-1] |
|||||||||
| Step 6: | j = j-1 |
||||||||
| Step 7: | a[j] = current_num | ||||||||
|
|||||||||
| Prev | |||||||||