Adding in bubble sort
This commit is contained in:
15
bubble-sort.py
Normal file
15
bubble-sort.py
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
def bubble_sort(nums):
|
||||||
|
swapping = True
|
||||||
|
end = len(nums)
|
||||||
|
while swapping:
|
||||||
|
swapping = False
|
||||||
|
for i in range(1, end):
|
||||||
|
if nums[i - 1] > nums[i]:
|
||||||
|
temp = nums[i - 1]
|
||||||
|
nums[i - 1] = nums[i]
|
||||||
|
nums[i] = temp
|
||||||
|
swapping = True
|
||||||
|
end -= 1
|
||||||
|
return nums
|
||||||
|
|
||||||
|
print(bubble_sort([5, 7, 3, 6, 8]))
|
||||||
Reference in New Issue
Block a user