-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsort.py
More file actions
50 lines (39 loc) · 1.1 KB
/
sort.py
File metadata and controls
50 lines (39 loc) · 1.1 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
from pathlib import Path
import sys
home = str(Path.home())
def main():
'''main'''
input=[4,3,2,1]
print(selection_sort(input))
# print(home)
def selection_sort(input):
new_list=input[:]
n = len(new_list)
for i in range(0,n - 1):
minIndex = i
for j in range(i + 1, n):
if new_list[j] < new_list[minIndex]:
minIndex = j
if minIndex != i:
new_list[i], new_list[minIndex]= new_list[minIndex],new_list[i]
return new_list
def insertion_sort(input):
new_list=input[:]
for i in range(1,len(new_list)):
key = new_list[i]
j = i - 1
while j >= 0 and new_list[j] > key:
new_list[j + 1] = new_list[j]
j = j - 1
new_list[j + 1] = key
return new_list
def bubble_sort(input):
new_list=input[:]
size=len(new_list)
for i in range(0,size-1):
for j in range(0,size-i-1):
if new_list[j]>new_list[j+1]:
new_list[j],new_list[j+1]=new_list[j+1],new_list[j]
return new_list
if __name__ == "__main__":
main()