sorting - insertion sort algorithm pseudocode -
insertion-sort(a) 1 j ← 2 length[a] 2 key ← a[j] 3 ▹ insert a[j] sorted sequence a[1 j - 1]. 4 ← j - 1 5 while > 0 , a[i] > key 6 a[i + 1] ← a[i] 7 ← - 1 8 a[i + 1] ← key
hi! first question.could me understand code? why 'a[i+1]=a[i]'? shouldn't other way round going down list.
a[i+1]=a[i]
used shift each element greater key
1 place right, can put key
before them.
you can find more information on page.
Comments
Post a Comment