Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def swap(list, a_idx, b_idx):
- temp = list[a_idx]
- list[a_idx] = list[b_idx]
- list[b_idx] = temp
- def selection_sort(list):
- for i in range(0, len(list)):
- max = list[0]
- max_idx = 0
- for j in range(1, len(list) - i):
- if(max < list[j]):
- max = list[j]
- max_idx = j
- last_place_idx = len(list) - 1 - i
- if(max_idx == last_place_idx):
- print("Max already in the last place!")
- else:
- swap(list, last_place_idx, max_idx)
- '''
- temp = list[last_place_idx]
- list[last_place_idx] = list[max_idx]
- list[max_idx] = temp
- '''
- list = [3,4,1,2,6,5]
- print("List at the start: " + str(list))
- selection_sort(list)
- print("List at the end: " + str(list))
- print("End")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement