sort list in desending order INPUT: list=list of values to be sorted n=size of list that contains values to be sorted OUTPUT: list of sorted values in desending order
(list, n)
| 35 | |
| 36 | |
| 37 | def insertion_sort_desc(list, n): |
| 38 | """ |
| 39 | sort list in desending order |
| 40 | |
| 41 | INPUT: |
| 42 | list=list of values to be sorted |
| 43 | n=size of list that contains values to be sorted |
| 44 | |
| 45 | OUTPUT: |
| 46 | list of sorted values in desending order |
| 47 | """ |
| 48 | for i in range(0, n): |
| 49 | key = list[i] |
| 50 | j = i - 1 |
| 51 | # Swap elements witth key iff they are |
| 52 | # greater than key |
| 53 | while j >= 0 and list[j] < key: |
| 54 | list[j + 1] = list[j] |
| 55 | j = j - 1 |
| 56 | list[j + 1] = key |
| 57 | return list |
| 58 | |
| 59 | |
| 60 | input_list() |