We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent f8fd6a6 commit be78520Copy full SHA for be78520
bubble_sort.py
@@ -0,0 +1,15 @@
1
+def bubble_sort(L):
2
+ print("unsorted:", L)
3
+ for i in range(len(L)):
4
+ for j in range(len(L)-1-i):
5
+ if L[j]>L[j+1]:
6
+ L[j], L[j+1] = L[j+1], L[j]
7
+ print(L)
8
+ else:
9
10
+ print()
11
+ return L
12
+
13
+L = [5,4,6,9,2,1]
14
+sort = bubble_sort(L)
15
+print("sorted:", sort)
insertion_sort.py
+def insertion_sort(L):
+ for i in range(1,len(L)):
+ current_element = L[i]
+ while current_element < L[i-1] and i > 0:
+ L[i] = L[i-1]
+ i = i - 1
+ L[i] = current_element
+sort = insertion_sort(L)
+print("sorted:",sort)
0 commit comments