Question

Using Python, reverse this insertion sort to sort from largest to smallest value. def insertionSort(alist): for...

Using Python, reverse this insertion sort to sort from largest to smallest value.

def insertionSort(alist):
for index in range(1,len(alist)):

currentvalue = alist[index]
position = index

while position>0 and alist[position-1]>currentvalue:
alist[position]=alist[position-1]
position = position-1

alist[position]=currentvalue

0 0
Add a comment Improve this question Transcribed image text
Answer #1
def insertionSort(alist):
    for index in range(1, len(alist)):
        currentvalue = alist[index]
        position = index
        while position > 0 and alist[position - 1] < currentvalue:
            alist[position] = alist[position - 1]
            position = position - 1
            alist[position] = currentvalue


Add a comment
Know the answer?
Add Answer to:
Using Python, reverse this insertion sort to sort from largest to smallest value. def insertionSort(alist): for...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT