-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsort.py
More file actions
49 lines (42 loc) · 945 Bytes
/
sort.py
File metadata and controls
49 lines (42 loc) · 945 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
39
40
41
42
43
44
45
46
47
48
49
# Buble Sort & Insertion Sort
# Insertion Sort
i = 1
L = []
y = int(input("Masukin Banyak Looping = "))
while i <= y:
print("Nilai",i,":",end=" ")
nilai = int(input(" "))
i = i + 1
L.append(nilai)
print("Inputan Nilai",L)
### Implementasi Insertion Sort
##
##x = len(L)
##for i in range(1,x):
## n = L[i]
## z = i - 1
## while z >=0 and L[z] < n:
## L[z+1] = L[z]
## z = z - 1
## L[z+1] = n
##print("Nilai Terurut = ",L)
#Buble Sort
x = len(L)
for i in range(x):
for y in range(x-i-1):
if L[y] > L[y+1]:
pindah = L[y]
L[y] = L[y+1]
L[y+1] = pindah
if (y%2==0):
bmedian = x / 2 -1
bmendianyo = int(bmedian)
hasil = [L[bmendianyo], L[bmendianyo+1]]
else :
bmendianyo = (y+1) / 2 - 1
bmendianyo = int(bmedian)
hasil = [L[bmendianyo]]
print("Sort =",L)
print("MIN = ",min(L))
print("MAX = ",max(L))
print("Median = ",hasil)