Advertisement
amigojapan

wikipedia's insertion sort pseudo code vs my rewording

Mar 23rd, 2017
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. wikipedia's insertion sort pseudo code is difficult to parse mentally for normal people:
  2. for i = 1 to length(A)
  3. j ← i
  4. while j > 0 and A[j-1] > A[j]
  5. swap A[j] and A[j-1]
  6. j ← j - 1
  7. end while
  8. end for
  9.  
  10. I think I came up with the easiest version of the sorting algorithm for people to parse mentally…. using my flowcharts… I took if form this pseudocode http://pastebin.com/VxKxZW5r , but I reworded the while condition to to SECOND > 0 AND A[FIRST] > A[SECOND] where FIRST=POS and SECOND=POS+1. then I did swap(FIRST,SECOND)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement