Skip to content

Commit 358aff4

Browse files
Added Insertion and Selection Sort functionality, and removed Bubble Sort test case
1 parent 323e835 commit 358aff4

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

BubbleSort.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,3 @@ def bubble_sort(unsorted):
77
unsorted[j] = temp
88

99
return unsorted
10-
11-
12-
print(bubble_sort([4, 2, 6, 5, 1, 3]))

InsertionSort.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
def insertion_sort(unsorted):
2+
for i in range(1, len(unsorted)):
3+
j = i-1
4+
current = unsorted[j+1]
5+
while current < unsorted[j] and j > -1:
6+
unsorted[j+1] = unsorted[j]
7+
unsorted[j] = current
8+
j -= 1
9+
10+
return unsorted

SelectionSort.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
def selection_sort(unsorted):
2+
for i in range(len(unsorted) - 1):
3+
min_index = i
4+
for j in range(i + 1, len(unsorted)):
5+
if unsorted[j] < unsorted[min_index]:
6+
min_index = j
7+
8+
if i != min_index:
9+
temp = unsorted[i]
10+
unsorted[i] = unsorted[min_index]
11+
unsorted[min_index] = temp
12+
13+
return unsorted

0 commit comments

Comments
 (0)