Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def shell_sort2(file_name, gap_list):
- """ Receives a list of gaps and runs shell sort with those gaps.
- If a gap is greater than the number of items then ignore and move to the next.
- Students need to:
- - complete the code for sorting. gap_insertion_sort is obviously still handy
- - Keep track of the total key comparisons used.
- """
- alist = load_file(file_name)
- count = 0
- # ---start student section---
- gap = len(gap_list) // 2
- while gap > 0: # build a list of gaps used as we go
- for start_position in range(gap):
- count += gap_insertion_sort(alist, start_position, gap)
- gap = gap // 2
- # ===end student section===
- print('Shellsort2 with gap list on {}, {} items'.format(file_name, len(alist)))
- print(' Used {} comparisons.'.format(count))
- print(' Gaps were {}: \n'.format(gap_list))
- return alist
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement