Advertisement
Guest User

Untitled

a guest
Sep 15th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 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 = load_file(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(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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement