-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreverse
More file actions
executable file
·38 lines (28 loc) · 884 Bytes
/
reverse
File metadata and controls
executable file
·38 lines (28 loc) · 884 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env python3
def reverse(lst: list, idx: int) -> None:
for i in range(idx):
if i > idx:
print(f'List after Reverse: {lst}')
return
lst[idx], lst[i] = lst[i], lst[idx]
idx -= 1
print(f'List after Reverse: {lst}')
def max(lst: list, idx1: int, idx2: int) -> int:
return idx1 if lst[idx1] > lst[idx2] else idx2
def reverse_sort(lst: list) -> None:
for i in range(len(lst) - 1, 0, -1):
max_value = i
for j in range(0, i):
if max(lst, j, max_value) == max_value:
max_value = j
if i == max_value:
continue
print(i, max_value)
reverse(lst, max_value)
reverse(lst, i)
print(f'Sorted List: {lst}')
def main() -> int:
nb_list = [5, 4, 2, 1, 3]
reverse_sort(nb_list)
if __name__ == "__main__":
exit(main())