Advertisement
Guest User

Untitled

a guest
Sep 15th, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. def shell_sort2(file_name, gap_list):
  2. """ Receives a list of gaps and runs shell sort with those gaps.
  3. If a gap is greater than the number of items then ignore and move to the next.
  4. Students need to:
  5. - complete the code for sorting. gap_insertion_sort is obviously still handy
  6. - Keep track of the total key comparisons used.
  7. """
  8. alist = (file_name)
  9. count = 0
  10. # ---start student section---
  11. gap = len(gap_list) // 2
  12. while gap > 0: # build a list of gaps used as we go
  13. for start_position in range(0, gap):
  14. count += gap_insertion_sort(alist, start_position, gap)
  15. gap = gap // 2
  16. # ===end student section===
  17. print('Shellsort2 with gap list on {}, {} items'.format(file_name, len(alist)))
  18. print(' Used {} comparisons.'.format(count))
  19. print(' Gaps were {}: \n'.format(gap_list))
  20. return alist
  21.  
  22. def main():
  23. """asdf"""
  24. length = 1500
  25. listf = []
  26. for item in range(0,length):
  27. listf.append(length - item)
  28. print(listf[0])
  29. print(listf[-1])
  30. selection = shell_sort2([9, 3, 10, 2, 7, 1, 0, 11, 6, 5, 8, 4],[3,1])
  31.  
  32. print(selection)
  33.  
  34. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement