Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
bubble sort complete
  • Loading branch information
Hunter315 committed Jan 16, 2019
commit b0fa7fcbce679a4d078e6d01d176be1f8d81995a
7 changes: 6 additions & 1 deletion project/iterative_sorting.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ def insertion_sort( arr ):

# STRETCH: implement the Bubble Sort function below
def bubble_sort( arr ):

for passnum in range(len(arr)-1,0,-1):
for i in range(passnum):
if arr[i]>arr[i+1]:
temp = arr[i]
arr[i] = arr[i+1]
arr[i+1] = temp
return arr


Expand Down
14 changes: 7 additions & 7 deletions project/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ def test_insertion(self):
self.assertEqual(insertion_sort(arr3), [0,1,2,3,4,5])


# def test_bubble(self):
# arr1 = [1, 5, 8, 4, 2, 9, 6, 0, 3, 7]
# arr2 = []
# arr3 = [0, 1, 2, 3, 4, 5]
def test_bubble(self):
arr1 = [1, 5, 8, 4, 2, 9, 6, 0, 3, 7]
arr2 = []
arr3 = [0, 1, 2, 3, 4, 5]

# self.assertEqual(bubble_sort(arr1), [0,1,2,3,4,5,6,7,8,9])
# self.assertEqual(bubble_sort(arr2), [])
# self.assertEqual(bubble_sort(arr3), [0,1,2,3,4,5])
self.assertEqual(bubble_sort(arr1), [0,1,2,3,4,5,6,7,8,9])
self.assertEqual(bubble_sort(arr2), [])
self.assertEqual(bubble_sort(arr3), [0,1,2,3,4,5])


# def test_count(self):
Expand Down