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 = (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(0, 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
- def main():
- """asdf"""
- length = 1500
- listf = []
- for item in range(0,length):
- listf.append(length - item)
- print(listf[0])
- print(listf[-1])
- selection = shell_sort2([9, 3, 10, 2, 7, 1, 0, 11, 6, 5, 8, 4],[3,1])
- print(selection)
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement