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

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -