in a typical sorting algorithm, the goal is to take random data and put it in order.
your task is the reverse, take an ordered bit of data, and do an "inverted" sort function.
for example, the reverse of merge sort might look like the following...
1 2 3 4 5 6 7 8 9 10 start
6 7 8 9 10 1 2 3 4 5 invert 1/2
7 6 10 9 8 2 1 5 4 3 invert 1/4
done.
here's the sort function you have to invert...
step = [1,2,3,5,8,13,21,34...]
maxindex = 0
while step[maxindex] < len(array):
maxindex += 1
maxindex -= 2
for k in range(maxindex,-1,-1):
h = step[k]
for i in range(len(array)-h,-1,-1):
i = j
while j+h < len(array) and array[j] > array[j+h]:
array[j],array[j+h] = array[j+h],array[j]
j += h
Question
Guest
in a typical sorting algorithm, the goal is to take random data and put it in order.
your task is the reverse, take an ordered bit of data, and do an "inverted" sort function.
for example, the reverse of merge sort might look like the following...
1 2 3 4 5 6 7 8 9 10 start
6 7 8 9 10 1 2 3 4 5 invert 1/2
7 6 10 9 8 2 1 5 4 3 invert 1/4
done.
here's the sort function you have to invert...
try it with 100 elements, and give me the result!
Edited by phillip1882Link to comment
Share on other sites
6 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.