Advertisement
avisrivastava254084

Untitled

Sep 25th, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.46 KB | None | 0 0
  1. def max_sort(arr, last_index):
  2.     if last_index == 0:
  3.         return arr
  4.     max_ = arr[0]
  5.     max_index = 0
  6.     for i in range(1, last_index+1):
  7.         if arr[i] > max_:
  8.             max_ = arr[i]
  9.             max_index = i
  10.     temp = arr[last_index]
  11.     arr[last_index] = arr[max_index]
  12.     arr[max_index] = temp
  13.     arr = max_sort(arr, last_index-1)
  14.     return arr
  15.  
  16.  
  17. print(max_sort([5, 4, 3, 2, 1], 4))
  18. print(max_sort([10, 9, 8, 3, 4, 5, 6, 7, 2, 1], 9))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement